Skip to content

Deprecate assert in import() - #63172

Merged
Jake Bailey (jakebailey) merged 3 commits into
microsoft:mainfrom
jakebailey:deprecate-assert-2
Mar 2, 2026
Merged

Deprecate assert in import()#63172
Jake Bailey (jakebailey) merged 3 commits into
microsoft:mainfrom
jakebailey:deprecate-assert-2

Conversation

@jakebailey

Copy link
Copy Markdown
Member

This was missed in #63077.

Perhaps slightly more dubious, given this isn't syntax per se, but interpreted at runtime?

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR deprecates the use of assert in TypeScript import type expressions, requiring developers to use the newer with keyword instead. This aligns with the broader JavaScript/TypeScript evolution toward import attributes.

Changes:

  • Updated test cases to use with instead of assert in import type expressions
  • Added deprecation diagnostic for assert usage in import types
  • Created new test files to verify deprecation warnings and ignore behavior

Reviewed changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated no comments.

Show a summary per file
FileDescription
tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmitErrors1.tsUpdated import type syntax from assert to with
tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmit1.tsUpdated import type syntax from assert to with
tests/cases/conformance/moduleResolution/resolutionModeImportType1.tsUpdated import type syntax from assert to with
tests/cases/compiler/parseAssertEntriesError.tsUpdated import type syntax from assert to with
tests/cases/compiler/importTypeAssertionDeprecationIgnored.tsNew test file verifying ignoreDeprecations: "6.0" suppresses the warning
tests/cases/compiler/importTypeAssertionDeprecation.tsNew test file demonstrating the deprecation warning for assert usage
tests/baselines/reference/*.typesUpdated baseline files reflecting the syntax changes
tests/baselines/reference/*.symbolsUpdated baseline files reflecting the syntax changes
tests/baselines/reference/*.errors.txtUpdated baseline files showing new deprecation errors for assert usage
tests/baselines/reference/*.jsUpdated baseline files with emitted JavaScript output
src/compiler/checker.tsAdded deprecation check for assert keyword in import type expressions
Comments suppressed due to low confidence (1)

tests/cases/compiler/importTypeAssertionDeprecation.ts:1

  • The comment on line 10 states 'Should be deprecated - uses 'assert' instead of 'with'', but the actual test file content shows line 11 also uses 'assert', while the comment on line 14 says 'Should be fine - uses 'with''. However, the baseline errors show both lines trigger deprecation errors. The test case comments are inconsistent with the actual test content - line 11 should use with if it's supposed to be 'fine'.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Feb 20, 2026

Copy link
Copy Markdown
Member

We don't have a test with { assert: { type: json } }???


// @Filename: /main.ts
type A = import("./types", { assert: { "resolution-mode": "import" } }).MyType;
type B = import("./types", { assert: { "resolution-mode": "require" } }).MyType;

Choose a reason for hiding this comment

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

These are both for qualified names - are import() type nodes also what we use in typeof import(...) and typeof import(...).someValue? If so, can we add tests for that too?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yeah, that's another construct I missed.

@github-project-automationgithub-project-automationBot moved this from Not started to Needs merge in PR BacklogFeb 21, 2026
@DanielRosenwasser

Copy link
Copy Markdown
Member

I assume we have tests for runtime import() calls as well.

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queueMar 2, 2026
Merged via the queue into microsoft:main with commit 206ed1aMar 2, 2026
23 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the deprecate-assert-2 branch March 2, 2026 22:03
@github-project-automationgithub-project-automationBot moved this from Needs merge to Done in PR BacklogMar 2, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@jakebailey@DanielRosenwasser@andrewbranch@typescript-bot