I would like to create a type that defines one static property and where other properties will have a different signature:
type Spec = {
[K in string]: K extends "foo"
? string
: string[];
};
const spec: Spec = {
foo: 'a',
bar: ['a'],
baz: ['b']
}
Apparently, the type checker ignores K extends "foo"
restriction and wants foo
property to be an array of strings instead of a string.
How can I solve that?