Skip to content

Commit

Permalink
Fix error message incorrectly referencing 'asserts' instead of 'asser…
Browse files Browse the repository at this point in the history
…t'. (#61066)
  • Loading branch information
DanielRosenwasser authored Jan 28, 2025
1 parent fed7a7f commit 0652664
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48156,7 +48156,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

if (moduleKind === ModuleKind.NodeNext && !isImportAttributes) {
return grammarErrorOnFirstToken(node, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_asserts);
return grammarErrorOnFirstToken(node, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert);
}

if (declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier) === ModuleKind.CommonJS) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3983,7 +3983,7 @@
"category": "Error",
"code": 2879
},
"Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.": {
"Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.": {
"category": "Error",
"code": 2880
},
Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/importAssertionNonstring.errors.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
mod.mts(1,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
mod.mts(1,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(1,37): error TS2322: Type '{ field: 0; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'number' is not assignable to type 'string'.
mod.mts(1,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(3,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
mod.mts(3,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(3,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(5,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
mod.mts(5,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(5,37): error TS2322: Type '{ field: RegExp; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'RegExp' is not assignable to type 'string'.
mod.mts(5,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(7,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
mod.mts(7,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(7,37): error TS2322: Type '{ field: string[]; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'string[]' is not assignable to type 'string'.
mod.mts(7,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(9,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
mod.mts(9,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(9,37): error TS2322: Type '{ field: { a: number; }; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type '{ a: number; }' is not assignable to type 'string'.
mod.mts(9,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(11,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
mod.mts(11,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(11,66): error TS2837: Import assertion values must be string literal expressions.


==== mod.mts (16 errors) ====
import * as thing1 from "./mod.mjs" assert {field: 0};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: 0; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
Expand All @@ -37,13 +37,13 @@ mod.mts(11,66): error TS2837: Import assertion values must be string literal exp

import * as thing2 from "./mod.mjs" assert {field: `a`};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~
!!! error TS2837: Import assertion values must be string literal expressions.

import * as thing3 from "./mod.mjs" assert {field: /a/g};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: RegExp; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
Expand All @@ -53,7 +53,7 @@ mod.mts(11,66): error TS2837: Import assertion values must be string literal exp

import * as thing4 from "./mod.mjs" assert {field: ["a"]};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: string[]; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
Expand All @@ -63,7 +63,7 @@ mod.mts(11,66): error TS2837: Import assertion values must be string literal exp

import * as thing5 from "./mod.mjs" assert {field: { a: 0 }};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: { a: number; }; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
Expand All @@ -73,6 +73,6 @@ mod.mts(11,66): error TS2837: Import assertion values must be string literal exp

import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()}
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~
!!! error TS2837: Import assertion values must be string literal expressions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
index.ts(1,35): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
otherc.cts(1,35): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
index.ts(1,35): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
otherc.cts(1,35): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.


==== index.ts (1 errors) ====
import json from "./package.json" assert { type: "json" };
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
==== otherc.cts (1 errors) ====
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
==== package.json (0 errors) ====
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/index.ts(6,50): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
/index.ts(6,50): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
/index.ts(7,14): error TS2305: Module '"pkg"' has no exported member 'ImportInterface'.
/index.ts(7,49): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
/index.ts(7,49): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.


==== /index.ts (3 errors) ====
Expand All @@ -11,12 +11,12 @@

import {type RequireInterface as Req} from "pkg" assert { "resolution-mode": "require" };
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" };
~~~~~~~~~~~~~~~
!!! error TS2305: Module '"pkg"' has no exported member 'ImportInterface'.
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
export interface Loc extends Req, Imp {}

export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/index.ts(6,14): error TS2305: Module '"pkg"' has no exported member 'RequireInterface'.
/index.ts(6,50): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
/index.ts(7,49): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
/index.ts(6,50): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
/index.ts(7,49): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.


==== /index.ts (3 errors) ====
Expand All @@ -13,10 +13,10 @@
~~~~~~~~~~~~~~~~
!!! error TS2305: Module '"pkg"' has no exported member 'RequireInterface'.
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
import {type ImportInterface as Imp} from "pkg" assert { "resolution-mode": "import" };
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
export interface Loc extends Req, Imp {}

export type { RequireInterface } from "pkg" assert { "resolution-mode": "require" };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
/index.ts(2,45): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
/index.ts(2,45): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
/index.ts(2,73): error TS1453: `resolution-mode` should be either `require` or `import`.
/index.ts(4,10): error TS2305: Module '"pkg"' has no exported member 'ImportInterface'.
/index.ts(4,39): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
/index.ts(6,76): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
/index.ts(4,39): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
/index.ts(6,76): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.


==== /index.ts (5 errors) ====
// incorrect mode
import type { RequireInterface } from "pkg" assert { "resolution-mode": "foobar" };
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~
!!! error TS1453: `resolution-mode` should be either `require` or `import`.
// not type-only
import { ImportInterface } from "pkg" assert { "resolution-mode": "import" };
~~~~~~~~~~~~~~~
!!! error TS2305: Module '"pkg"' has no exported member 'ImportInterface'.
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
// not exclusively type-only
import {type RequireInterface as Req, RequireInterface as Req2} from "pkg" assert { "resolution-mode": "require" };
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'asserts'.
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.

export interface LocalInterface extends RequireInterface, ImportInterface {}

Expand Down

0 comments on commit 0652664

Please sign in to comment.