Repository navigation
Exempt declare redeclarations from TS2729 use-before-init check #65518
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
刘亦达 (zhengdaodeguL)
wants to merge
1
commit into
microsoft:main
from
zhengdaodeguL:fix/ts2729-declare-redeclared-inherited-prop-65514
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...estdata/baselines/reference/compiler/useBeforeDeclaration_declareRedeclaration.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| useBeforeDeclaration_declareRedeclaration.ts(15,5): error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor. | ||
| useBeforeDeclaration_declareRedeclaration.ts(15,5): error TS2612: Property 'b' will overwrite the base property in 'Base'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration. | ||
| useBeforeDeclaration_declareRedeclaration.ts(16,14): error TS2729: Property 'b' is used before its initialization. | ||
|
|
||
|
|
||
| ==== useBeforeDeclaration_declareRedeclaration.ts (3 errors) ==== | ||
| class Base { | ||
| b: 1 = 1; | ||
| } | ||
|
|
||
| class Plain extends Base { | ||
| d = this.b; | ||
| } | ||
|
|
||
| class Narrowed extends Base { | ||
| declare b: 1; | ||
| d = this.b; | ||
| } | ||
|
|
||
| class Redeclared extends Base { | ||
| b: 1; | ||
| ~ | ||
| !!! error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor. | ||
| ~ | ||
| !!! error TS2612: Property 'b' will overwrite the base property in 'Base'. If this is intentional, add an initializer. Otherwise, add a 'declare' modifier or remove the redundant declaration. | ||
| d = this.b; | ||
| ~ | ||
| !!! error TS2729: Property 'b' is used before its initialization. | ||
| !!! related TS2728 useBeforeDeclaration_declareRedeclaration.ts:15:5: 'b' is declared here. | ||
| } | ||
|
|
37 changes: 37 additions & 0 deletions
37
tsc/testdata/baselines/reference/compiler/useBeforeDeclaration_declareRedeclaration.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //// [tests/cases/compiler/useBeforeDeclaration_declareRedeclaration.ts] //// | ||
|
|
||
| //// [useBeforeDeclaration_declareRedeclaration.ts] | ||
| class Base { | ||
| b: 1 = 1; | ||
| } | ||
|
|
||
| class Plain extends Base { | ||
| d = this.b; | ||
| } | ||
|
|
||
| class Narrowed extends Base { | ||
| declare b: 1; | ||
| d = this.b; | ||
| } | ||
|
|
||
| class Redeclared extends Base { | ||
| b: 1; | ||
| d = this.b; | ||
| } | ||
|
|
||
|
|
||
| //// [useBeforeDeclaration_declareRedeclaration.js] | ||
| "use strict"; | ||
| class Base { | ||
| b = 1; | ||
| } | ||
| class Plain extends Base { | ||
| d = this.b; | ||
| } | ||
| class Narrowed extends Base { | ||
| d = this.b; | ||
| } | ||
| class Redeclared extends Base { | ||
| b; | ||
| d = this.b; | ||
| } |
49 changes: 49 additions & 0 deletions
49
tsc/testdata/baselines/reference/compiler/useBeforeDeclaration_declareRedeclaration.symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| //// [tests/cases/compiler/useBeforeDeclaration_declareRedeclaration.ts] //// | ||
|
|
||
| === useBeforeDeclaration_declareRedeclaration.ts === | ||
| class Base { | ||
| >Base : Symbol(Base, Decl(useBeforeDeclaration_declareRedeclaration.ts, 0, 0)) | ||
|
|
||
| b: 1 = 1; | ||
| >b : Symbol(Base.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 0, 12)) | ||
| } | ||
|
|
||
| class Plain extends Base { | ||
| >Plain : Symbol(Plain, Decl(useBeforeDeclaration_declareRedeclaration.ts, 2, 1)) | ||
| >Base : Symbol(Base, Decl(useBeforeDeclaration_declareRedeclaration.ts, 0, 0)) | ||
|
|
||
| d = this.b; | ||
| >d : Symbol(Plain.d, Decl(useBeforeDeclaration_declareRedeclaration.ts, 4, 26)) | ||
| >this.b : Symbol(Base.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 0, 12)) | ||
| >this : Symbol(Plain, Decl(useBeforeDeclaration_declareRedeclaration.ts, 2, 1)) | ||
| >b : Symbol(Base.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 0, 12)) | ||
| } | ||
|
|
||
| class Narrowed extends Base { | ||
| >Narrowed : Symbol(Narrowed, Decl(useBeforeDeclaration_declareRedeclaration.ts, 6, 1)) | ||
| >Base : Symbol(Base, Decl(useBeforeDeclaration_declareRedeclaration.ts, 0, 0)) | ||
|
|
||
| declare b: 1; | ||
| >b : Symbol(Narrowed.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 8, 29)) | ||
|
|
||
| d = this.b; | ||
| >d : Symbol(Narrowed.d, Decl(useBeforeDeclaration_declareRedeclaration.ts, 9, 17)) | ||
| >this.b : Symbol(Narrowed.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 8, 29)) | ||
| >this : Symbol(Narrowed, Decl(useBeforeDeclaration_declareRedeclaration.ts, 6, 1)) | ||
| >b : Symbol(Narrowed.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 8, 29)) | ||
| } | ||
|
|
||
| class Redeclared extends Base { | ||
| >Redeclared : Symbol(Redeclared, Decl(useBeforeDeclaration_declareRedeclaration.ts, 11, 1)) | ||
| >Base : Symbol(Base, Decl(useBeforeDeclaration_declareRedeclaration.ts, 0, 0)) | ||
|
|
||
| b: 1; | ||
| >b : Symbol(Redeclared.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 13, 31)) | ||
|
|
||
| d = this.b; | ||
| >d : Symbol(Redeclared.d, Decl(useBeforeDeclaration_declareRedeclaration.ts, 14, 9)) | ||
| >this.b : Symbol(Redeclared.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 13, 31)) | ||
| >this : Symbol(Redeclared, Decl(useBeforeDeclaration_declareRedeclaration.ts, 11, 1)) | ||
| >b : Symbol(Redeclared.b, Decl(useBeforeDeclaration_declareRedeclaration.ts, 13, 31)) | ||
| } | ||
|
|
50 changes: 50 additions & 0 deletions
50
tsc/testdata/baselines/reference/compiler/useBeforeDeclaration_declareRedeclaration.types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| //// [tests/cases/compiler/useBeforeDeclaration_declareRedeclaration.ts] //// | ||
|
|
||
| === useBeforeDeclaration_declareRedeclaration.ts === | ||
| class Base { | ||
| >Base : Base | ||
|
|
||
| b: 1 = 1; | ||
| >b : 1 | ||
| >1 : 1 | ||
| } | ||
|
|
||
| class Plain extends Base { | ||
| >Plain : Plain | ||
| >Base : Base | ||
|
|
||
| d = this.b; | ||
| >d : 1 | ||
| >this.b : 1 | ||
| >this : this | ||
| >b : 1 | ||
| } | ||
|
|
||
| class Narrowed extends Base { | ||
| >Narrowed : Narrowed | ||
| >Base : Base | ||
|
|
||
| declare b: 1; | ||
| >b : 1 | ||
|
|
||
| d = this.b; | ||
| >d : 1 | ||
| >this.b : 1 | ||
| >this : this | ||
| >b : 1 | ||
| } | ||
|
|
||
| class Redeclared extends Base { | ||
| >Redeclared : Redeclared | ||
| >Base : Base | ||
|
|
||
| b: 1; | ||
| >b : 1 | ||
|
|
||
| d = this.b; | ||
| >d : 1 | ||
| >this.b : 1 | ||
| >this : this | ||
| >b : 1 | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tsc/testdata/tests/cases/compiler/useBeforeDeclaration_declareRedeclaration.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // @target: es2022 | ||
| // @strict: true | ||
| // @useDefineForClassFields: true | ||
|
|
||
| class Base { | ||
| b: 1 = 1; | ||
| } | ||
|
|
||
| class Plain extends Base { | ||
| d = this.b; | ||
| } | ||
|
|
||
| class Narrowed extends Base { | ||
| declare b: 1; | ||
| d = this.b; | ||
| } | ||
|
|
||
| class Redeclared extends Base { | ||
| b: 1; | ||
| d = this.b; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you update this test fixture