Property is not assignable to string index in interface
The presented best solution didn't work when I've tried to implement this interface. I ended up nesting part with dynamic key. Maybe someone will find it useful:
interface MultichannelConfiguration {
channels: {
[key: string]: Configuration;
}
defaultChannel: string;
}
You can use an intersection of two interfaces:
interface Api<T> {
[key: string]: T[];
}
type ApiType<T> = Api<T> & {
meta: Meta;
}
declare let x: ApiType<string>;
let a = x.meta // type of `a` is `Meta`
let b = x["meta"]; // type of `b` is `Meta`
let p = x["someotherindex"] // type of `p` is `string[]`
let q = x.someotherindex // type of `q` is `string[]`