Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43020,6 +43020,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,15 @@
/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'.


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

==== /main.ts (2 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'.

18 changes: 18 additions & 0 deletions tests/baselines/reference/importTypeAssertionDeprecation.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/importTypeAssertionDeprecation.ts] ////

=== /types.d.ts ===
export interface MyType { x: string }
>MyType : Symbol(MyType, Decl(types.d.ts, 0, 0))
>x : Symbol(MyType.x, Decl(types.d.ts, 0, 25))

=== /main.ts ===
// Should be deprecated - uses 'assert' instead of 'with'
type A = import("./types", { assert: { "resolution-mode": "import" } }).MyType;
>A : Symbol(A, Decl(main.ts, 0, 0))
>MyType : Symbol(MyType, Decl(types.d.ts, 0, 0))

// Should be fine - uses 'with'
type B = import("./types", { with: { "resolution-mode": "import" } }).MyType;
>B : Symbol(B, Decl(main.ts, 1, 79))
>MyType : Symbol(MyType, Decl(types.d.ts, 0, 0))

18 changes: 18 additions & 0 deletions tests/baselines/reference/importTypeAssertionDeprecation.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//// [tests/cases/compiler/importTypeAssertionDeprecation.ts] ////

=== /types.d.ts ===
export interface MyType { x: string }
>x : string
> : ^^^^^^

=== /main.ts ===
// Should be deprecated - uses 'assert' instead of 'with'
type A = import("./types", { assert: { "resolution-mode": "import" } }).MyType;
>A : import("./types").MyType
> : ^^^^^^^^^^^^^^^^^^^^^^^^

// Should be fine - uses 'with'
type B = import("./types", { with: { "resolution-mode": "import" } }).MyType;
>B : import("./types").MyType
> : ^^^^^^^^^^^^^^^^^^^^^^^^

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
Loading