I am facing an ambiguous TS-Error that I find challenging to resolve. It appears to be linked to the "noImplicitAny" and "strictNullChecks" settings in the TS-Config file. Can someone offer insight into what this error signifies and what message the compiler is conveying? Please provide not just a solution but also an explanation of the issue's complexity.
interface Person {
name: string;
age: number;
}
interface MyState {
someKeyA: string[];
someKeyB: Person | null;
isOk: boolean;
}
const getInitialState = (): MyState => {
return {
someKeyA: ["This is a wonderful state", "But sth is not right"],
someKeyB: {
name: "Francis",
age: 33
},
isOk: false
};
};
class MyWonderFullClass {
state: MyState;
constructor() {
this.state = getInitialState();
}
setSingleStateField = (
fieldId: keyof MyState,
value: MyState[keyof MyState]
) => {
if (!fieldId || !value) {
return;
}
this.state[fieldId] = value;
/*The assignment fails with the following error message: Type 'true | Person | string[]' is not assignable to type 'string[] & (Person | null) & boolean'. Type 'true' is not assignable to type 'string[] & (Person | null) & boolean'.*/
};
}
https://codesandbox.io/s/typescript-playground-export-forked-nijj9?file=/index.ts