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.
Comment on lines 7 to 8
assignmentCompatWithNumericIndexer.ts(30,9): error TS1184: Modifiers cannot appear here.
assignmentCompatWithNumericIndexer.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 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.

Copilot uses AI. Check for mistakes.
Comment on lines 5 to 6
assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(59,9): error TS1184: Modifiers cannot appear here.
assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(60,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 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.

Suggested change
assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(59,9): error TS1184: Modifiers cannot appear here.
assignmentCompatWithGenericCallSignaturesWithOptionalParameters.ts(60,9): error TS1184: Modifiers cannot appear here.

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.

}
}

let x!: string = 123
Copy link

Copilot AI Jan 8, 2026

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.

Suggested change
let x!: string = 123
let x: string = 123

Copilot uses AI. Check for mistakes.
Comment on lines 29 to 30
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.
Copy link

Copilot AI Jan 8, 2026

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) ====

Copilot uses AI. Check for mistakes.
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: Needs merge

Development

Successfully merging this pull request may close these issues.

4 participants