Skip to content

Conversation

@DanielRosenwasser
Copy link
Member

As part of #62333, this pull request updates a handful of tests so that they will not encounter the error

Variable 'x' is used before being assigned.

when we switch --strict on by default.

The typical changes you should expect are

  • a new declare modifier on the variable
  • a ! definite-assignment assertion
  • an initializer for the variable
  • occasionally an explicit strictness flag turned off

Some tests are left as-is though.

Copilot AI review requested due to automatic review settings January 7, 2026 00:24
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jan 7, 2026
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 7, 2026
Copy link
Contributor

Copilot AI left a 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 declare modifier 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

Comment on lines 1 to 3
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.
Copy link

Copilot AI Jan 7, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines 13 to 14
assignmentCompatWithStringIndexer2.ts(44,9): error TS1184: Modifiers cannot appear here.
assignmentCompatWithStringIndexer2.ts(45,9): error TS1184: Modifiers cannot appear here.
Copy link

Copilot AI Jan 7, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines 7 to 8
assignmentCompatWithNumericIndexer3.ts(31,9): error TS1184: Modifiers cannot appear here.
assignmentCompatWithNumericIndexer3.ts(32,9): error TS1184: Modifiers cannot appear here.
Copy link

Copilot AI Jan 7, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines 7 to 8
assignmentCompatWithNumericIndexer2.ts(30,9): error TS1184: Modifiers cannot appear here.
assignmentCompatWithNumericIndexer2.ts(31,9): error TS1184: Modifiers cannot appear here.
Copy link

Copilot AI Jan 7, 2026

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.

Copilot uses AI. Check for mistakes.
@github-project-automation github-project-automation bot moved this from Not started to Needs merge in PR Backlog Jan 7, 2026
@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Jan 8, 2026

I've reviewed the new error diffs in *.errors.txt matching [+-]\!\!|! and I don't see anything that jumps out.

@DanielRosenwasser
Copy link
Member Author

@copilot please review

Copy link
Contributor

Copilot AI commented Jan 8, 2026

@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.

@DanielRosenwasser
Copy link
Member Author

no no no no

Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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 no new comments.

@jakebailey
Copy link
Member

I am sort of confused why these changes are needed to switch strict; can you give an example of changes to look at or why they differ?

@DanielRosenwasser
Copy link
Member Author

@jakebailey our test suite has 2 issues that don't work with --strictNullChecks or --strictPropertyInitialization

  • Variables are assumed to be initialized just so we have a value of a given type
  • Class properties are assumed to be initialized for the same reason, or to avoid writing a constructor function

So the usual 4 solutions are the following:

  1. When valid, adding a declare modifier is almost always the preferred solution from what I've seen in most tests.
  2. For local variables and class properties, add a definitely-assigned assertion (!).
  3. If the expression is trivial enough and it does not impact the control flow analysis of types, add an initializer.
  4. Change the strictness settings.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what more can one say about a 1000+ file PR than "LGTM"

@DanielRosenwasser DanielRosenwasser added this pull request to the merge queue Jan 9, 2026
Merged via the queue into main with commit f5ccf43 Jan 9, 2026
33 checks passed
@DanielRosenwasser DanielRosenwasser deleted the testUpdatesForStrictInitialization branch January 9, 2026 23:57
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants