Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37952,6 +37952,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (importCallOptionsType !== emptyObjectType) {
checkTypeAssignableTo(optionsType, getNullableType(importCallOptionsType, TypeFlags.Undefined), node.arguments[1]);
}
if (compilerOptions.ignoreDeprecations !== "6.0" && isObjectLiteralExpression(node.arguments[1])) {
for (const prop of node.arguments[1].properties) {
if (isPropertyAssignment(prop) && isIdentifier(prop.name) && prop.name.escapedText === "assert") {
grammarErrorOnNode(prop.name, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert);
break;
}
}
}
}

// resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal
Expand Down Expand Up @@ -43020,6 +43028,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
checkSourceElement(node.argument);

if (node.attributes) {
if (node.attributes.token !== SyntaxKind.WithKeyword && compilerOptions.ignoreDeprecations !== "6.0") {
grammarErrorOnFirstToken(node.attributes, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert);
}
getResolutionModeOverride(node.attributes, grammarErrorOnNode);
}
checkTypeReferenceOrImport(node);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/main.ts(1,38): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
/main.ts(2,38): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
/main.ts(4,31): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
/main.ts(5,31): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.


==== /types.d.ts (0 errors) ====
export interface MyType { x: string }

==== /main.ts (4 errors) ====
type A = import("./types", { assert: { "resolution-mode": "import" } }).MyType;
~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
type B = import("./types", { assert: { "resolution-mode": "require" } }).MyType;
~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.

const a = import("./types", { assert: { "resolution-mode": "import" } });
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
const b = import("./types", { assert: { "resolution-mode": "require" } });
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export interface ImportInterface {}
export interface RequireInterface {}
//// [index.ts]
export type LocalInterface =
& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;

export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);


//// [index.js]
Expand All @@ -31,6 +31,6 @@ exports.b = null;


//// [index.d.ts]
export type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface;
export declare const a: import("pkg").RequireInterface;
export type LocalInterface = import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;
export declare const a: import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface;
export declare const b: import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
export type LocalInterface =
>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0))

& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0))

& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;
>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0))

export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
>a : Symbol(a, Decl(index.ts, 4, 12))
>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0))

export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);
>b : Symbol(b, Decl(index.ts, 5, 12))
>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ export type LocalInterface =
>LocalInterface : LocalInterface
> : ^^^^^^^^^^^^^^

& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;

export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
>a : import("pkg").RequireInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>(null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface) : import("pkg").RequireInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface : import("pkg").RequireInterface
>(null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface) : import("pkg").RequireInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface : import("pkg").RequireInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any : any

export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);
>b : import("./node_modules/pkg/import").ImportInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>(null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface) : import("./node_modules/pkg/import").ImportInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface : import("./node_modules/pkg/import").ImportInterface
>(null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface) : import("./node_modules/pkg/import").ImportInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface : import("./node_modules/pkg/import").ImportInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any : any

=== /node_modules/pkg/import.d.ts ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export interface ImportInterface {}
export interface RequireInterface {}
//// [index.ts]
export type LocalInterface =
& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;

export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);


//// [index.js]
Expand All @@ -31,6 +31,6 @@ exports.b = null;


//// [index.d.ts]
export type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface;
export declare const a: import("pkg").RequireInterface;
export type LocalInterface = import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;
export declare const a: import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface;
export declare const b: import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
export type LocalInterface =
>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0))

& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0))

& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;
>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0))

export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
>a : Symbol(a, Decl(index.ts, 4, 12))
>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0))

export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);
>b : Symbol(b, Decl(index.ts, 5, 12))
>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ export type LocalInterface =
>LocalInterface : LocalInterface
> : ^^^^^^^^^^^^^^

& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;

export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
>a : import("pkg").RequireInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>(null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface) : import("pkg").RequireInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface : import("pkg").RequireInterface
>(null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface) : import("pkg").RequireInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface : import("pkg").RequireInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any : any

export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);
>b : import("./node_modules/pkg/import").ImportInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>(null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface) : import("./node_modules/pkg/import").ImportInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface : import("./node_modules/pkg/import").ImportInterface
>(null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface) : import("./node_modules/pkg/import").ImportInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface : import("./node_modules/pkg/import").ImportInterface
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>null as any : any

=== /node_modules/pkg/import.d.ts ===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export interface ImportInterface {}
export interface RequireInterface {}
//// [index.ts]
export type LocalInterface =
& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;

export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);


//// [index.js]
Expand All @@ -31,6 +31,6 @@ exports.b = null;


//// [index.d.ts]
export type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface;
export declare const a: import("pkg").RequireInterface;
export type LocalInterface = import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;
export declare const a: import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface;
export declare const b: import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
export type LocalInterface =
>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0))

& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0))

& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;
>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0))

export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
>a : Symbol(a, Decl(index.ts, 4, 12))
>RequireInterface : Symbol(RequireInterface, Decl(require.d.ts, 0, 0))

export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);
>b : Symbol(b, Decl(index.ts, 5, 12))
>ImportInterface : Symbol(ImportInterface, Decl(import.d.ts, 0, 0))

Expand Down
Loading