I have this in one of my components:
public booleanSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);
When I add "strictFunctionTypes": true
to the tsconfig.json
file I get the following error:
× Compiling TypeScript sources through NGC
ERROR: path/to/my/component.component.ts:28:10 - error TS2322: Type 'BehaviorSubject<false>' is not assignable to type 'BehaviorSubject<boolean>'.
Types of property 'observers' are incompatible.
Type 'Observer<false>[]' is not assignable to type 'Observer<boolean>[]'.
Type 'Observer<false>' is not assignable to type 'Observer<boolean>'.
Type 'boolean' is not assignable to type 'false'.
28 public booleanSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);
Does anyone know the reason and how to get it not to throw the error by keeping the strictFunctionTypes
flag set to true
?
Normally when I create a BehaviorSubject I just assign a type to it when initializing it. Try to it like this:
public booleanSubject = new BehaviorSubject<boolean>(false);
Doing so it will initialize the BehaviorSubject type as boolean and I believe the error will go away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With