【发布时间】:2021-03-19 15:16:14
【问题描述】:
我的一个组件中有这个:
public booleanSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);
当我将"strictFunctionTypes": true 添加到tsconfig.json 文件时,我收到以下错误:
× 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);
有谁知道原因以及如何通过将strictFunctionTypes 标志设置为true 来使其不引发错误?
【问题讨论】:
标签: angular typescript tsconfig