【发布时间】:2021-04-29 14:10:53
【问题描述】:
我正在尝试按原样将此 google 动态表单用于 Angular 11,但出现错误。
这是逐字复制的所有代码,显然它可以在这里工作,但在我的开发机器上给了我错误。 https://stackblitz.com/edit/angular-sccsnu?file=src%2Fapp%2Fquestion-base.ts
√ 编译成功。
Error: src/app/_models/question-base.ts:21:5 - error TS2322: Type 'T | undefined' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'T | undefined'.
Type 'undefined' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'undefined'.
21 this.value = options.value;
~~~~~~~~~~
【问题讨论】:
-
你的 tsconfig.json 在开发机器上是不是不同?
-
您可以尝试将
!添加到this.value = options.value!;吗? -
Raz,已修复,谢谢,如果您将此作为答案而不是评论,我可以将其标记为正确。
-
很高兴它对你有用
标签: angular typescript