How to disable strict mode in Angular




Asked on December 16, 2023
When I start my Angular application, I am getting such type of errors.


[ERROR] TS2564: Property 'books' has no initializer and is not definitely assigned in the constructor. [plugin angular-compiler]


    src/app/add-book/add-book.component.ts:13:4:

      13 │     books: Book[];

         ╵     ~~~~~



[ERROR] TS2564: Property 'books' has no initializer and is not definitely assigned in the constructor. [plugin angular-compiler]


    src/app/home/home.component.ts:12:4:

      12 │     books: Book[];

         ╵     ~~~~~



[ERROR] TS2564: Property 'books' has no initializer and is not definitely assigned in the constructor. [plugin angular-compiler]


    src/app/manage-book/manage-book.component.ts:13:4:

      13 │     books: Book[];

         ╵     ~~~~~



How can I disable strict mode in Angular? I am using Angular version 17.



Replied on December 16, 2023
1. Go to tsconfig.json file in root directory of the project.

2.  Find "strict": true and make it false as below.

//tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "forceConsistentCasingInFileNames": true,
    "strict": false,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "declaration": false,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "ES2022",
    "module": "ES2022",
    "useDefineForClassFields": false,
    "lib": [
      "ES2022",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}




Replied on December 16, 2023
Thanks. It is working.

Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us