Skip to content

Comments

Deprecate assert in import()#63172

Open
jakebailey wants to merge 3 commits intomicrosoft:mainfrom
jakebailey:deprecate-assert-2
Open

Deprecate assert in import()#63172
jakebailey wants to merge 3 commits intomicrosoft:mainfrom
jakebailey:deprecate-assert-2

Conversation

@jakebailey
Copy link
Member

This was missed in #63077.

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

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 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
File Description
tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmitErrors1.ts Updated import type syntax from assert to with
tests/cases/conformance/node/nodeModulesImportTypeModeDeclarationEmit1.ts Updated import type syntax from assert to with
tests/cases/conformance/moduleResolution/resolutionModeImportType1.ts Updated import type syntax from assert to with
tests/cases/compiler/parseAssertEntriesError.ts Updated import type syntax from assert to with
tests/cases/compiler/importTypeAssertionDeprecationIgnored.ts New test file verifying ignoreDeprecations: "6.0" suppresses the warning
tests/cases/compiler/importTypeAssertionDeprecation.ts New test file demonstrating the deprecation warning for assert usage
tests/baselines/reference/*.types Updated baseline files reflecting the syntax changes
tests/baselines/reference/*.symbols Updated baseline files reflecting the syntax changes
tests/baselines/reference/*.errors.txt Updated baseline files showing new deprecation errors for assert usage
tests/baselines/reference/*.js Updated baseline files with emitted JavaScript output
src/compiler/checker.ts Added 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
Copy link
Member

DanielRosenwasser commented Feb 20, 2026

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;
Copy link
Member

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
Member Author

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-automation github-project-automation bot moved this from Not started to Needs merge in PR Backlog Feb 21, 2026
@DanielRosenwasser
Copy link
Member

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

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.

3 participants