I basically understand TS2322, but in this case, I don't get it.
I have a given class definition like this:
export class MyFaultyClass {
functionOrNull: () => void | null;
constructor() {
this.functionOrNull = null; // <- here comes the error TS2322
}
}
My question
Why can't I assign null to the defined property?
My expectation
constructor() {
this.functionOrNull = null; // OR
this.functionOrNull = () => {};
}
Edit
Here is a "working" example: typescriptlang.org/playground Needs strictNullChecks to be enabled.