I want to set the object attribute to be either a boolean value or an boolean array value depending on the props.
But it shows an error when the key value is received as a variable rather than a literal string value.
I don't know the difference between two.
export interface State {
a: {
[key: string]: any[];
};
b: {
[key: string]: boolean | boolean[];
};
}
const state:State = {
a: {},
b: {},
}
const key:string = "test key";
// this works
let test1 = typeof state.b["test key"] === 'object' && state.a["test key"][0];
// type error : Property '0' does not exist on type 'boolean | boolean[]
let test2 = typeof state.b[key] === 'object' && state.b[key][0];