In Typescript you can declare that all elements in an array are of the same type like this:
const theArray: MyInterface[]
Is there anything similar you can do that declares that ALL of an object's property values must be of the same type? (without specifying every property name)
For example, I'm currently doing this:
interface MyInterface {
name:string;
}
const allTheThingsCurrently = {
first: <MyInterface>{name: 'first thing name' },
second: <MyInterface>{name: 'second thing name' },
third: <MyInterface>{name: 'third thing name' },
//...
};
...note how I have to specify <MyInterface>
for every single property. Is there any kind of shortcut for this? i.e. I'm imagining something like this...
const allTheThingsWanted:MyInterface{} = {
first: {name: 'first thing name' },
second: {name: 'second thing name' },
third: {name: 'third thing name' },
//...
};
MyInterface{}
is the part that's invalid code and I'm looking for a way to do with less redundancy, and optionally the extra strictness that prevents any other properties being adding to the object of a differing type.