type Config = {
[key: string]: {
client: string,
connection: Object,
models: Object,
},
def: string;
}
const config: Config = {
def: `mysql`,
mysql: {
client: "mysql",
connection: {
host: 'host',
port: 'port',
// ...
},
models: {}
}
}
throws:
Property 'def' of type 'string' is not assignable to 'string' index type '{ client: string; connection: Object; models: Object; }'.
Type '{ def: string; mysql: { client: string; connection: { host: string; port: string; }; models: {}; }; }' is not assignable to type 'Config'.
Property 'def' is incompatible with index signature.
Type 'string' is not assignable to type '{ client: string; connection: Object; models: Object; }'.
but I need to define type where def will be string type and any other value under any possible other key will be specific object. Any ideas how to achieve it?
Typescript playground with above example:
Edit:
I think I know what is happening here, why this is not covered, this comment on github describes it well:
https://github.com/microsoft/TypeScript/issues/17867#issuecomment-547940152