Proposal: Always allow type-only imports to reference .ts extensions (#54746)

This commit is contained in:
Andrew Branch
2023-07-24 16:12:38 -07:00
committed by GitHub
parent 55fcee407a
commit 2170e6c6cc
9 changed files with 271 additions and 2 deletions

View File

@@ -0,0 +1,23 @@
// @allowImportingTsExtensions: false
// @target: esnext
// @module: esnext
// @Filename: a.ts
export class A {}
// @Filename: a.d.ts
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
// @Filename: c.ts
import type { A } from "./a.d.ts"; // ok
import {} from "./a.d.ts"; // error
import { type A as _A } from "./a.d.ts"; // error
type __A = import("./a.d.ts").A; // ok
const aPromise = import("./a.d.ts"); // error

View File

@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
// @module: nodenext
// @allowImportingTsExtensions: false
// @Filename: /exports.ts
//// export interface SomeInterface {}
//// export class SomePig {}
// @Filename: /a.ts
//// import type { SomePig } from "./exports.ts";
//// new SomePig/**/
verify.completions({
marker: "",
includes: [{
name: "SomePig",
source: completion.CompletionSource.TypeOnlyAlias,
hasAction: true,
}]
});
verify.applyCodeActionFromCompletion("", {
name: "SomePig",
source: completion.CompletionSource.TypeOnlyAlias,
description: `Remove 'type' from import declaration from "./exports.ts"`,
newFileContent:
`import { SomePig } from "./exports.js";
new SomePig`,
preferences: {
includeCompletionsForModuleExports: true,
allowIncompleteCompletions: true,
includeInsertTextCompletions: true,
},
});

View File

@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />
// @module: nodenext
// @allowImportingTsExtensions: true
// @Filename: /exports.ts
//// export interface SomeInterface {}
//// export class SomePig {}
// @Filename: /a.ts
//// import type { SomePig } from "./exports.ts";
//// new SomePig/**/
verify.completions({
marker: "",
includes: [{
name: "SomePig",
source: completion.CompletionSource.TypeOnlyAlias,
hasAction: true,
}]
});
verify.applyCodeActionFromCompletion("", {
name: "SomePig",
source: completion.CompletionSource.TypeOnlyAlias,
description: `Remove 'type' from import declaration from "./exports.ts"`,
newFileContent:
`import { SomePig } from "./exports.ts";
new SomePig`,
preferences: {
includeCompletionsForModuleExports: true,
allowIncompleteCompletions: true,
includeInsertTextCompletions: true,
},
});