-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Always allow type-only imports to reference .ts extensions #54746
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
b.ts(2,16): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. | ||
b.ts(3,30): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. | ||
b.ts(5,25): error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. | ||
|
||
|
||
==== a.ts (0 errors) ==== | ||
export class A {} | ||
|
||
==== b.ts (3 errors) ==== | ||
import type { A } from "./a.ts"; // ok | ||
import {} from "./a.ts"; // error | ||
~~~~~~~~ | ||
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. | ||
import { type A as _A } from "./a.ts"; // error | ||
~~~~~~~~ | ||
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. | ||
type __A = import("./a.ts").A; // ok | ||
const aPromise = import("./a.ts"); // error | ||
~~~~~~~~ | ||
!!! error TS5097: An import path can only end with a '.ts' extension when 'allowImportingTsExtensions' is enabled. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//// [tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts] //// | ||
|
||
//// [a.ts] | ||
export class A {} | ||
|
||
//// [b.ts] | ||
import type { A } from "./a.ts"; // ok | ||
import {} from "./a.ts"; // error | ||
import { type A as _A } from "./a.ts"; // error | ||
type __A = import("./a.ts").A; // ok | ||
const aPromise = import("./a.ts"); // error | ||
|
||
|
||
//// [a.js] | ||
export class A { | ||
} | ||
//// [b.js] | ||
const aPromise = import("./a.ts"); // error | ||
export {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts] //// | ||
|
||
=== a.ts === | ||
export class A {} | ||
>A : Symbol(A, Decl(a.ts, 0, 0)) | ||
|
||
=== b.ts === | ||
import type { A } from "./a.ts"; // ok | ||
>A : Symbol(A, Decl(b.ts, 0, 13)) | ||
|
||
import {} from "./a.ts"; // error | ||
import { type A as _A } from "./a.ts"; // error | ||
>A : Symbol(A, Decl(a.ts, 0, 0)) | ||
>_A : Symbol(_A, Decl(b.ts, 2, 8)) | ||
|
||
type __A = import("./a.ts").A; // ok | ||
>__A : Symbol(__A, Decl(b.ts, 2, 38)) | ||
>A : Symbol(A, Decl(a.ts, 0, 0)) | ||
|
||
const aPromise = import("./a.ts"); // error | ||
>aPromise : Symbol(aPromise, Decl(b.ts, 4, 5)) | ||
>"./a.ts" : Symbol("a", Decl(a.ts, 0, 0)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [tests/cases/conformance/externalModules/typeOnly/allowsImportingTsExtension.ts] //// | ||
|
||
=== a.ts === | ||
export class A {} | ||
>A : A | ||
|
||
=== b.ts === | ||
import type { A } from "./a.ts"; // ok | ||
>A : A | ||
|
||
import {} from "./a.ts"; // error | ||
import { type A as _A } from "./a.ts"; // error | ||
>A : typeof A | ||
>_A : typeof A | ||
|
||
type __A = import("./a.ts").A; // ok | ||
>__A : A | ||
|
||
const aPromise = import("./a.ts"); // error | ||
>aPromise : Promise<typeof import("a")> | ||
>import("./a.ts") : Promise<typeof import("a")> | ||
>"./a.ts" : "./a.ts" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @allowImportingTsExtensions: false | ||
// @target: esnext | ||
// @module: esnext | ||
|
||
// @Filename: a.ts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there already an equivalent test case of the 5 assertions below for the case where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, but I'll add one here so it can be compared easily |
||
export class A {} | ||
|
||
// @Filename: b.ts | ||
import type { A } from "./a.ts"; // ok | ||
import {} from "./a.ts"; // error | ||
import { type A as _A } from "./a.ts"; // error | ||
type __A = import("./a.ts").A; // ok | ||
const aPromise = import("./a.ts"); // error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting i would have expected above two to be not errors per your description since its not in emitted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s a bit of a gray area, but I decided to treat this as if
verbatimModuleSyntax
is enabled. Depending on settings, this import could get preserved asimport {} from "./a.ts"
, whereasimport type
is unambiguously elided. It feels better to rely on the strong, unambiguous signal that the import will always be elided.