I'm providing a public Interface to my data, but for performance and memory reasons I want to use an Object and definitely not a Class. There's no code on the Interface, it is purely a data structure.
I want to be able to declare my Object as using the Interface so that if I change the Interface it'll show up as an error and doesn't get missed.
interface DataStructure { key1: string; key2: number; key3: boolean; key4: null; } const defaultData: {[key: string]: PropertyDescriptor} = { key1: {writable: true, enumerable: true}, key2: {writable: true, enumerable: true}, key3: {writable: true, enumerable: true} }; var myData = Object.create(null, defaultData);
I want this to report an error for missing key4
in the defaultData
Object, but can't quite figure out how right now.
(This is needed due to potentially tens of thousands of objects needing the same structure, and not wanting to waste GC on them when it's easier to just re-use them - also wanting simply Map stores, so no need for the Object prototype chain.)
class SimpleDataStructure implements DataStructure
?var myData: DataStructure = Object.create(null, defaultData);
?null
instead.Object.create
returnsany
- so there's nothing for it to complain about ;-)