Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 11 Type undefined is not assignable to type '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;
       ~~~~~~~~~~
like image 771
fizgig Avatar asked Jan 25 '21 18:01

fizgig


2 Answers

Adding ! to ‘this.value = options.value!;’ should fix it because ‘!’ operator indicate this value isn’t nullable.

like image 196
Raz Ronen Avatar answered Nov 15 '22 08:11

Raz Ronen


You can get rid of all the errors of "Type 'T | undefined' is not assignable to type 'T'" by setting the property "strict" in tsconfig.json file to false

like image 21
Mohamad Alkhalil Avatar answered Nov 15 '22 08:11

Mohamad Alkhalil