Skip to content

Commit e60635e

Browse files
committed
Deprecate assert in import()
1 parent 3472548 commit e60635e

File tree

47 files changed

+514
-340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+514
-340
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43020,6 +43020,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4302043020
checkSourceElement(node.argument);
4302143021

4302243022
if (node.attributes) {
43023+
if (node.attributes.token !== SyntaxKind.WithKeyword && compilerOptions.ignoreDeprecations !== "6.0") {
43024+
grammarErrorOnFirstToken(node.attributes, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert);
43025+
}
4302343026
getResolutionModeOverride(node.attributes, grammarErrorOnNode);
4302443027
}
4302543028
checkTypeReferenceOrImport(node);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/main.ts(1,38): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
2+
/main.ts(2,38): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
3+
4+
5+
==== /types.d.ts (0 errors) ====
6+
export interface MyType { x: string }
7+
8+
==== /main.ts (2 errors) ====
9+
type A = import("./types", { assert: { "resolution-mode": "import" } }).MyType;
10+
~
11+
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
12+
type B = import("./types", { assert: { "resolution-mode": "require" } }).MyType;
13+
~
14+
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
15+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/importTypeAssertionDeprecation.ts] ////
2+
3+
=== /types.d.ts ===
4+
export interface MyType { x: string }
5+
>MyType : Symbol(MyType, Decl(types.d.ts, 0, 0))
6+
>x : Symbol(MyType.x, Decl(types.d.ts, 0, 25))
7+
8+
=== /main.ts ===
9+
// Should be deprecated - uses 'assert' instead of 'with'
10+
type A = import("./types", { assert: { "resolution-mode": "import" } }).MyType;
11+
>A : Symbol(A, Decl(main.ts, 0, 0))
12+
>MyType : Symbol(MyType, Decl(types.d.ts, 0, 0))
13+
14+
// Should be fine - uses 'with'
15+
type B = import("./types", { with: { "resolution-mode": "import" } }).MyType;
16+
>B : Symbol(B, Decl(main.ts, 1, 79))
17+
>MyType : Symbol(MyType, Decl(types.d.ts, 0, 0))
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/importTypeAssertionDeprecation.ts] ////
2+
3+
=== /types.d.ts ===
4+
export interface MyType { x: string }
5+
>x : string
6+
> : ^^^^^^
7+
8+
=== /main.ts ===
9+
// Should be deprecated - uses 'assert' instead of 'with'
10+
type A = import("./types", { assert: { "resolution-mode": "import" } }).MyType;
11+
>A : import("./types").MyType
12+
> : ^^^^^^^^^^^^^^^^^^^^^^^^
13+
14+
// Should be fine - uses 'with'
15+
type B = import("./types", { with: { "resolution-mode": "import" } }).MyType;
16+
>B : import("./types").MyType
17+
> : ^^^^^^^^^^^^^^^^^^^^^^^^
18+

tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export interface ImportInterface {}
1515
export interface RequireInterface {}
1616
//// [index.ts]
1717
export type LocalInterface =
18-
& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
19-
& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
18+
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
19+
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;
2020

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

2424

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

3232

3333
//// [index.d.ts]
34-
export type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface;
35-
export declare const a: import("pkg").RequireInterface;
34+
export type LocalInterface = import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;
35+
export declare const a: import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface;
3636
export declare const b: import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;

tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).symbols

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
export type LocalInterface =
55
>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0))
66

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

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

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

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

tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node16).types

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ export type LocalInterface =
55
>LocalInterface : LocalInterface
66
> : ^^^^^^^^^^^^^^
77

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

11-
export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
11+
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
1212
>a : import("pkg").RequireInterface
1313
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
>(null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface) : import("pkg").RequireInterface
15-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16-
>null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface : import("pkg").RequireInterface
14+
>(null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface) : import("pkg").RequireInterface
1715
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
>null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface : import("pkg").RequireInterface
17+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818
>null as any : any
1919

20-
export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
20+
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);
2121
>b : import("./node_modules/pkg/import").ImportInterface
2222
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23-
>(null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface) : import("./node_modules/pkg/import").ImportInterface
24-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25-
>null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface : import("./node_modules/pkg/import").ImportInterface
23+
>(null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface) : import("./node_modules/pkg/import").ImportInterface
2624
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
>null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface : import("./node_modules/pkg/import").ImportInterface
26+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727
>null as any : any
2828

2929
=== /node_modules/pkg/import.d.ts ===

tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node18).js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export interface ImportInterface {}
1515
export interface RequireInterface {}
1616
//// [index.ts]
1717
export type LocalInterface =
18-
& import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface
19-
& import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface;
18+
& import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface
19+
& import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface;
2020

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

2424

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

3232

3333
//// [index.d.ts]
34-
export type LocalInterface = import("pkg", { assert: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { assert: { "resolution-mode": "import" } }).ImportInterface;
35-
export declare const a: import("pkg").RequireInterface;
34+
export type LocalInterface = import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface & import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;
35+
export declare const a: import("pkg", { with: { "resolution-mode": "require" } }).RequireInterface;
3636
export declare const b: import("pkg", { with: { "resolution-mode": "import" } }).ImportInterface;

tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node18).symbols

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
export type LocalInterface =
55
>LocalInterface : Symbol(LocalInterface, Decl(index.ts, 0, 0))
66

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

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

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

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

tests/baselines/reference/nodeModulesImportTypeModeDeclarationEmit1(module=node18).types

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ export type LocalInterface =
55
>LocalInterface : LocalInterface
66
> : ^^^^^^^^^^^^^^
77

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

11-
export const a = (null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface);
11+
export const a = (null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface);
1212
>a : import("pkg").RequireInterface
1313
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
>(null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface) : import("pkg").RequireInterface
15-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16-
>null as any as import("pkg", { assert: {"resolution-mode": "require"} }).RequireInterface : import("pkg").RequireInterface
14+
>(null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface) : import("pkg").RequireInterface
1715
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
>null as any as import("pkg", { with: {"resolution-mode": "require"} }).RequireInterface : import("pkg").RequireInterface
17+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818
>null as any : any
1919

20-
export const b = (null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface);
20+
export const b = (null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface);
2121
>b : import("./node_modules/pkg/import").ImportInterface
2222
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23-
>(null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface) : import("./node_modules/pkg/import").ImportInterface
24-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25-
>null as any as import("pkg", { assert: {"resolution-mode": "import"} }).ImportInterface : import("./node_modules/pkg/import").ImportInterface
23+
>(null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface) : import("./node_modules/pkg/import").ImportInterface
2624
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25+
>null as any as import("pkg", { with: {"resolution-mode": "import"} }).ImportInterface : import("./node_modules/pkg/import").ImportInterface
26+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727
>null as any : any
2828

2929
=== /node_modules/pkg/import.d.ts ===

0 commit comments

Comments
 (0)