'Angular dynamic forms project migration - 'input' has no initializer and not constructor, another error of Type T | undefined
Angular dynamic forms project migration - error of Type T | undefined
I've been looking for an example project for building angular forms based on JSON datasets and found this project https://github.com/dkreider/advanced-dynamic-angular-form
Everything builds and works correctly for advanced-dynamic-angular-form project on my local machine. Figured I would migrate the code into a starter project and in doing that get a better understanding of what is happening. After creating a new project and migrating the code over I receive one error in a class file, form-field.ts.
Error: src/app/model/form-field.ts:27: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'. Line: 27 this.value = options.value;
Direct link to file in github project https://github.com/dkreider/advanced-dynamic-angular-form/blob/master/src/app/form-field.ts
My thinking is that it should work in my new project without having to change any code. It must be some project config setting or compiler options? I've compared the angular.json, tsconfig.json, package.json between the two projects and can't see any real diffences.
Here is a link to download my starter project, formTest. And a direct link to form-fields.js in my formTest project Can't help but feel like I'm missing something basic.
Thanks for any help or a point in the right direction.
Solution 1:[1]
Ok, so the compiler option in tsconfig.json, “strict”: true. After I found this config difference between the projects did some searching about angular’s strict compiler option and found this.
Removed “strict”:true and added each strict option in my tsconfig.js. In this case, “strickNullCheck”:true was causing my formsTest project to fail.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Sum Dood |