Angular11Typeundefinedisnotassignabletotype'T'
I am trying to use this google dynamic form for Angular 11 as is and I get errors.
Here is all the code copied verbatim, obviously it works here but is giving me errors on my dev machine.
https://stackblitz.com/edit/angular-sccsnu?file=src%2Fapp%2Fquestion-base.ts
? Compiled successfully.
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;
~~~~~~~~~~
回答
添加!'this.value = options.value!;' 应该修复它,因为“!” 运算符指示此值不可为空。
THE END
二维码