PacktPublishing / ASP.NET-Core-2-and-Angular-5

ASP.NET Core 2 and Angular 5, published by Packt
MIT License
79 stars 75 forks source link

quiz-list.component.ts #24

Closed pokerclan closed 6 years ago

pokerclan commented 6 years ago

With code from the repository I can reproduce the error on any chapter. The four lines starting at @Input are the lines with the errors.

Visual Studio Community 2017

export class QuizListComponent implements OnInit {

@Input() class: string;

title: string;

selectedQuiz: Quiz;

quizzes: Quiz[];

Severity Code Description Project File Line Suppression State Error TS2564 (TS) Property 'class' has no initializer and is not definitely assigned in the constructor. TestMakerFreeWebApp_Chapter_02 (tsconfig project) C:\Users\JWPok\source\repos\Core2angular5\ASP.NET-Core-2-and-Angular-5-master\TestMakerFreeWebApp_Chapter_02\ClientApp\app\components\quiz\quiz-list.component.ts 23 Active

Error TS2564 (TS) Property 'quizzes' has no initializer and is not definitely assigned in the constructor. TestMakerFreeWebApp_Chapter_02 (tsconfig project) C:\Users\JWPok\source\repos\Core2angular5\ASP.NET-Core-2-and-Angular-5-master\TestMakerFreeWebApp_Chapter_02\ClientApp\app\components\quiz\quiz-list.component.ts 29 Active

Error TS2564 (TS) Property 'selectedQuiz' has no initializer and is not definitely assigned in the constructor. TestMakerFreeWebApp_Chapter_02 (tsconfig project) C:\Users\JWPok\source\repos\Core2angular5\ASP.NET-Core-2-and-Angular-5-master\TestMakerFreeWebApp_Chapter_02\ClientApp\app\components\quiz\quiz-list.component.ts 27 Active

Error TS2564 (TS) Property 'title' has no initializer and is not definitely assigned in the constructor. TestMakerFreeWebApp_Chapter_02 (tsconfig project) C:\Users\JWPok\source\repos\Core2angular5\ASP.NET-Core-2-and-Angular-5-master\TestMakerFreeWebApp_Chapter_02\ClientApp\app\components\quiz\quiz-list.component.ts 25 Active

Darkseal commented 6 years ago

Hello there and thank you for purchasing the book.

Are you using TypeScript 2.7 by any chance? That build introduced the strictPropertyInitialization flag (set to true by default) which could cause these kind of errors.

If you're using TS 2.7, try to turn it off by adding a "strictPropertyInitialization": false setting to the compilerOptions object in your tsconfig.json file: if that doesn't fix it, try to temporarily downgrade to TS 2.6 and see if the error persists.

I also made a post on my blog explaining the issue and enumerating some possible workarounds/fixes.

References