-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Test updates for strict initialization #62958
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This pull request updates TypeScript test baseline files to prepare for enabling --strict mode by default. The changes add declare modifiers to variable declarations that lack initializers, preventing "Variable 'x' is used before being assigned" errors when strict initialization checking is enabled.
Key Changes:
- Added
declaremodifier to uninitialized variable declarations in test baselines - Updated line number references in symbol tables and error messages to reflect the position changes
- Removed generated JavaScript variable declarations for declared variables (as they don't emit code)
Reviewed changes
Copilot reviewed 296 out of 2293 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
Multiple .types files |
Added declare modifier to variable declarations in type baseline files |
Multiple .symbols files |
Updated symbol declaration references to reflect new line positions after adding declare |
Multiple .js files |
Removed variable declarations that are now declared (don't emit to JavaScript) |
Multiple .errors.txt files |
Updated line numbers and added new errors for declare modifier usage in function scopes |
| assignmentCompatWithStringIndexer3.ts(7,16): error TS2304: Cannot find name 'A'. | ||
| assignmentCompatWithStringIndexer3.ts(18,9): error TS1184: Modifiers cannot appear here. | ||
| assignmentCompatWithStringIndexer3.ts(19,9): error TS1184: Modifiers cannot appear here. |
Copilot
AI
Jan 7, 2026
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.
The baseline file shows new TS1184 errors about modifiers not being allowed inside function scopes. The declare modifier cannot be used inside function bodies - it's only valid at the top level or in ambient contexts. These test cases with declare var inside the foo function are invalid and will fail when strict mode is enabled.
| assignmentCompatWithStringIndexer2.ts(44,9): error TS1184: Modifiers cannot appear here. | ||
| assignmentCompatWithStringIndexer2.ts(45,9): error TS1184: Modifiers cannot appear here. |
Copilot
AI
Jan 7, 2026
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.
Similar to Comment 1, the baseline shows TS1184 errors for declare modifiers inside the function scope. These need to use definite assignment assertions (!) or initializers instead of declare when inside function bodies.
| assignmentCompatWithNumericIndexer3.ts(31,9): error TS1184: Modifiers cannot appear here. | ||
| assignmentCompatWithNumericIndexer3.ts(32,9): error TS1184: Modifiers cannot appear here. |
Copilot
AI
Jan 7, 2026
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.
The baseline shows TS1184 errors for declare modifiers used inside function scopes. The declare modifier is not valid inside function bodies and should be replaced with definite assignment assertions or initializers.
| assignmentCompatWithNumericIndexer2.ts(30,9): error TS1184: Modifiers cannot appear here. | ||
| assignmentCompatWithNumericIndexer2.ts(31,9): error TS1184: Modifiers cannot appear here. |
Copilot
AI
Jan 7, 2026
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.
The baseline includes TS1184 errors showing that declare modifiers cannot appear inside function bodies. These variables should use definite assignment assertions or be given initializers instead.
| assignmentCompatWithNumericIndexer.ts(30,9): error TS1184: Modifiers cannot appear here. | ||
| assignmentCompatWithNumericIndexer.ts(31,9): error TS1184: Modifiers cannot appear here. |
Copilot
AI
Jan 7, 2026
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.
The baseline shows TS1184 errors for declare modifiers inside function scopes. Variables declared inside functions cannot use the declare modifier and should instead use definite assignment assertions (!) or initializers.
| assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(59,9): error TS1184: Modifiers cannot appear here. | ||
| assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(60,9): error TS1184: Modifiers cannot appear here. |
Copilot
AI
Jan 7, 2026
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.
The baseline shows TS1184 errors indicating that declare modifiers are not allowed inside function bodies. These variables need to use definite assignment assertions or initializers instead of the declare modifier.
| assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(59,9): error TS1184: Modifiers cannot appear here. | |
| assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(60,9): error TS1184: Modifiers cannot appear here. |
|
I've reviewed the new error diffs in |
|
@copilot please review |
|
@DanielRosenwasser I've opened a new pull request, #62964, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
no no no no |
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.
Pull request overview
Copilot reviewed 299 out of 2295 changed files in this pull request and generated 2 comments.
| } | ||
| } | ||
|
|
||
| let x!: string = 123 |
Copilot
AI
Jan 8, 2026
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.
Variable declaration combines definite assignment assertion (!) with an initializer (= 123), which is invalid TypeScript syntax. This should either use declare let x: string; or let x: string = 123; without the assertion, as the initializer already provides definite assignment.
| let x!: string = 123 | |
| let x: string = 123 |
| assignmentCompatWithStringIndexer.ts(55,5): error TS2322: Type 'number' is not assignable to type 'string'. | ||
| assignmentCompatWithStringIndexer.ts(55,6): error TS1263: Declarations with initializers cannot also have definite assignment assertions. |
Copilot
AI
Jan 8, 2026
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.
The error indicates that the code contains an invalid syntax combination: a definite assignment assertion with an initializer. This confirms the issue in the corresponding source baseline file.
See below for a potential fix:
==== assignmentCompatWithStringIndexer.ts (9 errors) ====
As part of #62333, this pull request updates a handful of tests so that they will not encounter the error
when we switch
--stricton by default.The typical changes you should expect are
declaremodifier on the variable!definite-assignment assertionSome tests are left as-is though.