Conversation
| computed = this.num * 10; | ||
| ~~~ | ||
| !!! error TS2729: Property 'num' is used before its initialization. | ||
| !!! related TS2728 tests/cases/compiler/useBeforeDeclaration_propertyDeclaration.ts:2:5: 'num' is declared here. |
There was a problem hiding this comment.
Should we tack on another related span to this message that says where num is initialized, since that's what the error is about?
weswigham
left a comment
There was a problem hiding this comment.
Seems good - I have a comment on the related span we're reporting (it seems to point at a not-so-useful location), but that's probably an existing issue (should we open a bug for it?).
|
@rbuckton is this ready to merge after it's brought up to date with master? |
|
The failing test has an interesting case: class A {
a: number;
b = this.a; // Error
~
!!! error TS2729: Property 'a' is used before its initialization.
!!! related TS2728 tests/cases/compiler/initializerWithThisPropertyAccess.ts:2:5: 'a' is declared here.
c = () => this.a;
d = (new A()).a;
~
!!! error TS2729: Property 'a' is used before its initialization.
!!! related TS2728 tests/cases/compiler/initializerWithThisPropertyAccess.ts:2:5: 'a' is declared here.
constructor() {
this.a = 1;
}
}This first case of |
# Conflicts: # src/compiler/checker.ts
|
I'm accepting the error as is for now since its still essentially true (its initialization is circular, so no 'a' will ever be initialized when trying to initialize |
|
This was superceded by #38030 |
Reports an error when referencing an uninitialized instance property from the initializer of another instance property when in
--strictNullChecksand--strictPropertyInitialization.Fixes #31223