Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
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
7 changes: 7 additions & 0 deletions 7 src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
9 changes: 9 additions & 0 deletions 9 tests/baselines/reference/exportSpecifiers_js.errors.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions 7 tests/baselines/reference/exportSpecifiers_js.symbols
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions 8 tests/baselines/reference/exportSpecifiers_js.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/conformance/externalModules/typeOnly/a.js ===
const foo = 0;
>foo : 0
>0 : 0

export { type foo };
>foo : 0

11 changes: 11 additions & 0 deletions 11 tests/baselines/reference/importSpecifiers_js.errors.txt
Original file line number Diff line number Diff line change
@@ -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 changes: 8 additions & 0 deletions 8 tests/baselines/reference/importSpecifiers_js.symbols
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions 7 tests/baselines/reference/importSpecifiers_js.types
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true

// @Filename: ./a.js
const foo = 0;
export { type foo };
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true

// @Filename: ./a.ts
export interface A {}

// @Filename: ./a.js
import { type A } from "./a";
Morty Proxy This is a proxified and sanitized view of the page, visit original site.