mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 02:33:53 -06:00
fix(48445): show errors on type-only import/export specifiers in JavaScript files (#48449)
This commit is contained in:
parent
d962091d94
commit
bf7bfa1b3f
@ -2273,6 +2273,13 @@ namespace ts {
|
||||
return "skip";
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
if ((node as ImportOrExportSpecifier).isTypeOnly) {
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics._0_declarations_can_only_be_used_in_TypeScript_files, isImportSpecifier(node) ? "import...type" : "export...type"));
|
||||
return "skip";
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
diagnostics.push(createDiagnosticForNode(node, Diagnostics.import_can_only_be_used_in_TypeScript_files));
|
||||
return "skip";
|
||||
|
||||
9
tests/baselines/reference/exportSpecifiers_js.errors.txt
Normal file
9
tests/baselines/reference/exportSpecifiers_js.errors.txt
Normal file
@ -0,0 +1,9 @@
|
||||
tests/cases/conformance/externalModules/typeOnly/a.js(2,10): error TS8006: 'export...type' declarations can only be used in TypeScript files.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/typeOnly/a.js (1 errors) ====
|
||||
const foo = 0;
|
||||
export { type foo };
|
||||
~~~~~~~~
|
||||
!!! error TS8006: 'export...type' declarations can only be used in TypeScript files.
|
||||
|
||||
7
tests/baselines/reference/exportSpecifiers_js.symbols
Normal file
7
tests/baselines/reference/exportSpecifiers_js.symbols
Normal file
@ -0,0 +1,7 @@
|
||||
=== tests/cases/conformance/externalModules/typeOnly/a.js ===
|
||||
const foo = 0;
|
||||
>foo : Symbol(foo, Decl(a.js, 0, 5))
|
||||
|
||||
export { type foo };
|
||||
>foo : Symbol(foo, Decl(a.js, 1, 8))
|
||||
|
||||
8
tests/baselines/reference/exportSpecifiers_js.types
Normal file
8
tests/baselines/reference/exportSpecifiers_js.types
Normal file
@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/externalModules/typeOnly/a.js ===
|
||||
const foo = 0;
|
||||
>foo : 0
|
||||
>0 : 0
|
||||
|
||||
export { type foo };
|
||||
>foo : 0
|
||||
|
||||
11
tests/baselines/reference/importSpecifiers_js.errors.txt
Normal file
11
tests/baselines/reference/importSpecifiers_js.errors.txt
Normal file
@ -0,0 +1,11 @@
|
||||
tests/cases/conformance/externalModules/typeOnly/a.js(1,10): error TS8006: 'import...type' declarations can only be used in TypeScript files.
|
||||
|
||||
|
||||
==== tests/cases/conformance/externalModules/typeOnly/a.ts (0 errors) ====
|
||||
export interface A {}
|
||||
|
||||
==== tests/cases/conformance/externalModules/typeOnly/a.js (1 errors) ====
|
||||
import { type A } from "./a";
|
||||
~~~~~~
|
||||
!!! error TS8006: 'import...type' declarations can only be used in TypeScript files.
|
||||
|
||||
8
tests/baselines/reference/importSpecifiers_js.symbols
Normal file
8
tests/baselines/reference/importSpecifiers_js.symbols
Normal file
@ -0,0 +1,8 @@
|
||||
=== tests/cases/conformance/externalModules/typeOnly/a.ts ===
|
||||
export interface A {}
|
||||
>A : Symbol(A, Decl(a.ts, 0, 0))
|
||||
|
||||
=== tests/cases/conformance/externalModules/typeOnly/a.js ===
|
||||
import { type A } from "./a";
|
||||
>A : Symbol(A, Decl(a.js, 0, 8))
|
||||
|
||||
7
tests/baselines/reference/importSpecifiers_js.types
Normal file
7
tests/baselines/reference/importSpecifiers_js.types
Normal file
@ -0,0 +1,7 @@
|
||||
=== tests/cases/conformance/externalModules/typeOnly/a.ts ===
|
||||
export interface A {}
|
||||
No type information for this code.
|
||||
No type information for this code.=== tests/cases/conformance/externalModules/typeOnly/a.js ===
|
||||
import { type A } from "./a";
|
||||
>A : any
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @Filename: ./a.js
|
||||
const foo = 0;
|
||||
export { type foo };
|
||||
@ -0,0 +1,9 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @Filename: ./a.ts
|
||||
export interface A {}
|
||||
|
||||
// @Filename: ./a.js
|
||||
import { type A } from "./a";
|
||||
Loading…
x
Reference in New Issue
Block a user