New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tour of Heros tutorial causes error in ch 3 when TS transpiler is set to "strict" #40941
Comments
Not explicitly setting the `hero` property as an optional property causes a compilation error: `Property 'hero' has no initializer and is not definitely assigned in the constructor` when having the ts transpiler set to "strict" mode.
docs: fix issue angular#40941 <body> setting the `hero` property as an optional property fixes the compilation error: `Property 'hero' has no initializer and is not definitely assigned in the constructor` when having the ts transpiler set to "strict" mode.
setting the `hero` property as an optional property fixes the compilation error: `Property 'hero' has no initializer and is not definitely assigned in the constructor` when having the ts transpiler set to "strict" mode.
Yes, this is a known issue. Many examples do not work in strict mode. This is being tracked in #39344. |
setting the `hero` property as an optional property fixes the compilation error: `Property 'hero' has no initializer and is not definitely assigned in the constructor` when having the ts transpiler set to "strict" mode.
There's another issue later in the tutorial when you get to
It complains id might be null and there's no fix other than handling it explicitly. On that subject the tutorial is a bit broken when it comes to error handling there. What if id really is not provided? What if it's not a number? What if there is no hero with that id? I really don't know, I'm new here. |
You just need to use |
@cfsamson if issue is fixed, can we close this ? |
Yes, thanks @iRealNirmal |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
馃摎 Docs or angular.io bug report
Description
The example code provided in Tutorial of Heros, chapter 3, section: Add the Input() hero property causes an error stating that "Property 'hero' has no initializer and is not definitely assigned in the constructor".
This might be caused by specifying "strict" mode when generating the app. Probably related to: #39966 (which seems to be fixed now)
It's caused by adding the line:
Specifying that
hero
is an optional property fixes the problem:馃敩 Minimal Reproduction
Follow the tutorial choosing strict when asked by
ng new
or by setting"strict": true
in tsconfig.json:What's the affected URL?**
https://angular.io/tutorial/toh-pt3#add-the-input-hero-property
Expected vs Actual Behavior**
Expected the tutorial to work, even though setting the ts transpiler to strict mode.
馃敟 Exception or Error
馃實 Your Environment
Browser info
The error is not browser specific.
Anything else relevant?
When asked by
ng new
if you want to enable strict mode, a lot of readers will choose "yes" since type checking and correctness it's part of what TypeScript promises to improve. Fixing the error requires some prior knowledge that tutorial readers might not have.The text was updated successfully, but these errors were encountered: