I have an object literal that maps key-value pairs. Is it possible to restrict the index signature key to a range of pre-defined values?
I tried the following but no error gets thrown when using the unspecified key "c":
let foo: { [key in 'a' | 'b']: any };
foo['c']; // no error
Updated:
The example above will throw an error when using "noImplicitAny" (see comments below).
In my code I'm actually using a variable instead of a hard coded value, so (I guess) Typescript can't know in advance if given value is allowed or not:
let foo: { [key in 'a' | 'b']: any };
foo[someDynamicKey]; // no error