I'm trying to figure out the syntax to define a type (interface) of an object's key.
Couldn't find how to do it on StackOverflow or anywhere else.
I have crafted this method, it works but I find it clumsy. Is there any "official" syntax for it?
interface Report {
action: string;
exists?: boolean;
warnings? : string[];
errors? : string[];
}
let patent: Patent = {
numbers: { … },
dates : { … },
report: ( ():Report => ({ // This works, it enforces the key's type but looks ugly
action : "create",
exists : false,
otherKey : "otherValue" // Typescript detects this wrong key, that's good
}))()
}