mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Proposal: Always allow type-only imports to reference .ts extensions (#54746)
This commit is contained in:
@@ -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
|
||||
34
tests/cases/fourslash/completionsImport_promoteTypeOnly6.ts
Normal file
34
tests/cases/fourslash/completionsImport_promoteTypeOnly6.ts
Normal 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,
|
||||
},
|
||||
});
|
||||
34
tests/cases/fourslash/completionsImport_promoteTypeOnly7.ts
Normal file
34
tests/cases/fourslash/completionsImport_promoteTypeOnly7.ts
Normal 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,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user