diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f29e12ff288ba..fdc9b72d4be44 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4961,14 +4961,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { error(errorNode, resolutionDiagnostic, moduleReference, resolvedModule.resolvedFileName); } else { - const tsExtension = tryExtractTSExtension(moduleReference); const isExtensionlessRelativePathImport = pathIsRelative(moduleReference) && !hasExtension(moduleReference); const resolutionIsNode16OrNext = moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext; - if (tsExtension) { - errorOnTSExtensionImport(tsExtension); - } - else if (!getResolveJsonModule(compilerOptions) && + if (!getResolveJsonModule(compilerOptions) && fileExtensionIs(moduleReference, Extension.Json) && moduleResolutionKind !== ModuleResolutionKind.Classic && hasJsonModuleEmitEnabled(compilerOptions)) { @@ -4993,11 +4989,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } return undefined; - function errorOnTSExtensionImport(tsExtension: string) { - const diag = Diagnostics.An_import_path_cannot_end_with_a_0_extension_Consider_importing_1_instead; - error(errorNode, diag, tsExtension, getSuggestedImportSource(tsExtension)); - } - function getSuggestedImportSource(tsExtension: string) { const importSourceWithoutExtension = removeExtension(moduleReference, tsExtension); /** diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 838c4fd0afc3f..e0e6f0077a976 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3026,10 +3026,6 @@ "category": "Error", "code": 2690 }, - "An import path cannot end with a '{0}' extension. Consider importing '{1}' instead.": { - "category": "Error", - "code": 2691 - }, "'{0}' is a primitive, but '{1}' is a wrapper object. Prefer using '{0}' when possible.": { "category": "Error", "code": 2692 diff --git a/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=bundler).errors.txt b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=bundler).errors.txt new file mode 100644 index 0000000000000..755f0d6eebda9 --- /dev/null +++ b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=bundler).errors.txt @@ -0,0 +1,32 @@ +/c.ts(1,16): error TS2307: Cannot find module './thisfiledoesnotexist.ts' or its corresponding type declarations. + + +==== /ts.ts (0 errors) ==== + export {}; + +==== /tsx.tsx (0 errors) ==== + export {}; + +==== /dts.d.ts (0 errors) ==== + export {}; + +==== /b.ts (0 errors) ==== + import {} from "./ts.js"; + import {} from "./ts.ts"; + import type {} from "./ts.d.ts"; + + import {} from "./tsx.js"; + import {} from "./tsx.jsx"; + import {} from "./tsx.ts"; + import {} from "./tsx.tsx"; + import type {} from "./tsx.d.ts"; + + import {} from "./dts.js"; + import {} from "./dts.ts"; + import type {} from "./dts.d.ts"; + +==== /c.ts (1 errors) ==== + import {} from "./thisfiledoesnotexist.ts"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './thisfiledoesnotexist.ts' or its corresponding type declarations. + \ No newline at end of file diff --git a/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=classic).errors.txt b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=classic).errors.txt new file mode 100644 index 0000000000000..ae5bc45ff3c2e --- /dev/null +++ b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=classic).errors.txt @@ -0,0 +1,32 @@ +/c.ts(1,16): error TS2792: Cannot find module './thisfiledoesnotexist.ts'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + + +==== /ts.ts (0 errors) ==== + export {}; + +==== /tsx.tsx (0 errors) ==== + export {}; + +==== /dts.d.ts (0 errors) ==== + export {}; + +==== /b.ts (0 errors) ==== + import {} from "./ts.js"; + import {} from "./ts.ts"; + import type {} from "./ts.d.ts"; + + import {} from "./tsx.js"; + import {} from "./tsx.jsx"; + import {} from "./tsx.ts"; + import {} from "./tsx.tsx"; + import type {} from "./tsx.d.ts"; + + import {} from "./dts.js"; + import {} from "./dts.ts"; + import type {} from "./dts.d.ts"; + +==== /c.ts (1 errors) ==== + import {} from "./thisfiledoesnotexist.ts"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2792: Cannot find module './thisfiledoesnotexist.ts'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option? + \ No newline at end of file diff --git a/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=node10).errors.txt b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=node10).errors.txt new file mode 100644 index 0000000000000..755f0d6eebda9 --- /dev/null +++ b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=node10).errors.txt @@ -0,0 +1,32 @@ +/c.ts(1,16): error TS2307: Cannot find module './thisfiledoesnotexist.ts' or its corresponding type declarations. + + +==== /ts.ts (0 errors) ==== + export {}; + +==== /tsx.tsx (0 errors) ==== + export {}; + +==== /dts.d.ts (0 errors) ==== + export {}; + +==== /b.ts (0 errors) ==== + import {} from "./ts.js"; + import {} from "./ts.ts"; + import type {} from "./ts.d.ts"; + + import {} from "./tsx.js"; + import {} from "./tsx.jsx"; + import {} from "./tsx.ts"; + import {} from "./tsx.tsx"; + import type {} from "./tsx.d.ts"; + + import {} from "./dts.js"; + import {} from "./dts.ts"; + import type {} from "./dts.d.ts"; + +==== /c.ts (1 errors) ==== + import {} from "./thisfiledoesnotexist.ts"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './thisfiledoesnotexist.ts' or its corresponding type declarations. + \ No newline at end of file diff --git a/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=node16).errors.txt b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=node16).errors.txt new file mode 100644 index 0000000000000..755f0d6eebda9 --- /dev/null +++ b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=node16).errors.txt @@ -0,0 +1,32 @@ +/c.ts(1,16): error TS2307: Cannot find module './thisfiledoesnotexist.ts' or its corresponding type declarations. + + +==== /ts.ts (0 errors) ==== + export {}; + +==== /tsx.tsx (0 errors) ==== + export {}; + +==== /dts.d.ts (0 errors) ==== + export {}; + +==== /b.ts (0 errors) ==== + import {} from "./ts.js"; + import {} from "./ts.ts"; + import type {} from "./ts.d.ts"; + + import {} from "./tsx.js"; + import {} from "./tsx.jsx"; + import {} from "./tsx.ts"; + import {} from "./tsx.tsx"; + import type {} from "./tsx.d.ts"; + + import {} from "./dts.js"; + import {} from "./dts.ts"; + import type {} from "./dts.d.ts"; + +==== /c.ts (1 errors) ==== + import {} from "./thisfiledoesnotexist.ts"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './thisfiledoesnotexist.ts' or its corresponding type declarations. + \ No newline at end of file diff --git a/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=nodenext).errors.txt b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=nodenext).errors.txt new file mode 100644 index 0000000000000..755f0d6eebda9 --- /dev/null +++ b/tests/baselines/reference/allowImportingTsExtensions(moduleresolution=nodenext).errors.txt @@ -0,0 +1,32 @@ +/c.ts(1,16): error TS2307: Cannot find module './thisfiledoesnotexist.ts' or its corresponding type declarations. + + +==== /ts.ts (0 errors) ==== + export {}; + +==== /tsx.tsx (0 errors) ==== + export {}; + +==== /dts.d.ts (0 errors) ==== + export {}; + +==== /b.ts (0 errors) ==== + import {} from "./ts.js"; + import {} from "./ts.ts"; + import type {} from "./ts.d.ts"; + + import {} from "./tsx.js"; + import {} from "./tsx.jsx"; + import {} from "./tsx.ts"; + import {} from "./tsx.tsx"; + import type {} from "./tsx.d.ts"; + + import {} from "./dts.js"; + import {} from "./dts.ts"; + import type {} from "./dts.d.ts"; + +==== /c.ts (1 errors) ==== + import {} from "./thisfiledoesnotexist.ts"; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2307: Cannot find module './thisfiledoesnotexist.ts' or its corresponding type declarations. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationFileForTsJsImport.errors.txt b/tests/baselines/reference/declarationFileForTsJsImport.errors.txt index 9acc28949a14d..abd3a14af6f2b 100644 --- a/tests/baselines/reference/declarationFileForTsJsImport.errors.txt +++ b/tests/baselines/reference/declarationFileForTsJsImport.errors.txt @@ -1,15 +1,15 @@ tests/cases/conformance/nonjsExtensions/main.ts(1,18): error TS2307: Cannot find module './file.js' or its corresponding type declarations. tests/cases/conformance/nonjsExtensions/main.ts(2,18): error TS2307: Cannot find module './file.jsx' or its corresponding type declarations. -tests/cases/conformance/nonjsExtensions/main.ts(3,18): error TS2691: An import path cannot end with a '.ts' extension. Consider importing './file.js' instead. -tests/cases/conformance/nonjsExtensions/main.ts(4,18): error TS2691: An import path cannot end with a '.tsx' extension. Consider importing './file.js' instead. +tests/cases/conformance/nonjsExtensions/main.ts(3,18): error TS2307: Cannot find module './file.ts' or its corresponding type declarations. +tests/cases/conformance/nonjsExtensions/main.ts(4,18): error TS2307: Cannot find module './file.tsx' or its corresponding type declarations. tests/cases/conformance/nonjsExtensions/main.ts(5,18): error TS2307: Cannot find module './file.mjs' or its corresponding type declarations. tests/cases/conformance/nonjsExtensions/main.ts(6,18): error TS2307: Cannot find module './file.cjs' or its corresponding type declarations. -tests/cases/conformance/nonjsExtensions/main.ts(7,18): error TS2691: An import path cannot end with a '.mts' extension. Consider importing './file.mjs' instead. -tests/cases/conformance/nonjsExtensions/main.ts(8,18): error TS2691: An import path cannot end with a '.cts' extension. Consider importing './file.cjs' instead. -tests/cases/conformance/nonjsExtensions/main.ts(9,18): error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './file.js' instead. -tests/cases/conformance/nonjsExtensions/main.ts(10,19): error TS2691: An import path cannot end with a '.d.cts' extension. Consider importing './file.js' instead. -tests/cases/conformance/nonjsExtensions/main.ts(11,19): error TS2691: An import path cannot end with a '.d.mts' extension. Consider importing './file.js' instead. -tests/cases/conformance/nonjsExtensions/main.ts(12,19): error TS2691: An import path cannot end with a '.ts' extension. Consider importing './file.d.json.js' instead. +tests/cases/conformance/nonjsExtensions/main.ts(7,18): error TS2307: Cannot find module './file.mts' or its corresponding type declarations. +tests/cases/conformance/nonjsExtensions/main.ts(8,18): error TS2307: Cannot find module './file.cts' or its corresponding type declarations. +tests/cases/conformance/nonjsExtensions/main.ts(9,18): error TS2307: Cannot find module './file.d.ts' or its corresponding type declarations. +tests/cases/conformance/nonjsExtensions/main.ts(10,19): error TS2307: Cannot find module './file.d.cts' or its corresponding type declarations. +tests/cases/conformance/nonjsExtensions/main.ts(11,19): error TS2307: Cannot find module './file.d.mts' or its corresponding type declarations. +tests/cases/conformance/nonjsExtensions/main.ts(12,19): error TS2307: Cannot find module './file.d.json.ts' or its corresponding type declarations. ==== tests/cases/conformance/nonjsExtensions/package.json (0 errors) ==== @@ -23,10 +23,10 @@ tests/cases/conformance/nonjsExtensions/main.ts(12,19): error TS2691: An import !!! error TS2307: Cannot find module './file.jsx' or its corresponding type declarations. import def3 from "./file.ts"; ~~~~~~~~~~~ -!!! error TS2691: An import path cannot end with a '.ts' extension. Consider importing './file.js' instead. +!!! error TS2307: Cannot find module './file.ts' or its corresponding type declarations. import def4 from "./file.tsx"; ~~~~~~~~~~~~ -!!! error TS2691: An import path cannot end with a '.tsx' extension. Consider importing './file.js' instead. +!!! error TS2307: Cannot find module './file.tsx' or its corresponding type declarations. import def5 from "./file.mjs"; ~~~~~~~~~~~~ !!! error TS2307: Cannot find module './file.mjs' or its corresponding type declarations. @@ -35,22 +35,22 @@ tests/cases/conformance/nonjsExtensions/main.ts(12,19): error TS2691: An import !!! error TS2307: Cannot find module './file.cjs' or its corresponding type declarations. import def7 from "./file.mts"; ~~~~~~~~~~~~ -!!! error TS2691: An import path cannot end with a '.mts' extension. Consider importing './file.mjs' instead. +!!! error TS2307: Cannot find module './file.mts' or its corresponding type declarations. import def8 from "./file.cts"; ~~~~~~~~~~~~ -!!! error TS2691: An import path cannot end with a '.cts' extension. Consider importing './file.cjs' instead. +!!! error TS2307: Cannot find module './file.cts' or its corresponding type declarations. import def9 from "./file.d.ts"; ~~~~~~~~~~~~~ -!!! error TS2691: An import path cannot end with a '.d.ts' extension. Consider importing './file.js' instead. +!!! error TS2307: Cannot find module './file.d.ts' or its corresponding type declarations. import def10 from "./file.d.cts"; ~~~~~~~~~~~~~~ -!!! error TS2691: An import path cannot end with a '.d.cts' extension. Consider importing './file.js' instead. +!!! error TS2307: Cannot find module './file.d.cts' or its corresponding type declarations. import def11 from "./file.d.mts"; ~~~~~~~~~~~~~~ -!!! error TS2691: An import path cannot end with a '.d.mts' extension. Consider importing './file.js' instead. +!!! error TS2307: Cannot find module './file.d.mts' or its corresponding type declarations. import def12 from "./file.d.json.ts"; ~~~~~~~~~~~~~~~~~~ -!!! error TS2691: An import path cannot end with a '.ts' extension. Consider importing './file.d.json.js' instead. +!!! error TS2307: Cannot find module './file.d.json.ts' or its corresponding type declarations. ==== tests/cases/conformance/nonjsExtensions/file.d.js.ts (0 errors) ==== declare var bad: "bad1"; export default bad; diff --git a/tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js b/tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js index 112d52257d6c1..6bed0c3f158bb 100644 --- a/tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js +++ b/tests/baselines/reference/tsserver/plugins/getSupportedCodeFixes-can-be-proxied.js @@ -1029,7 +1029,6 @@ Info 32 [00:01:13.000] response: "2685", "2687", "2688", - "2691", "2692", "2694", "2695", diff --git a/tests/cases/conformance/moduleResolution/allowImportingTsExtensions.ts b/tests/cases/conformance/moduleResolution/allowImportingTsExtensions.ts index 24004050d2de0..96d0786d0344b 100644 --- a/tests/cases/conformance/moduleResolution/allowImportingTsExtensions.ts +++ b/tests/cases/conformance/moduleResolution/allowImportingTsExtensions.ts @@ -27,3 +27,6 @@ import type {} from "./tsx.d.ts"; import {} from "./dts.js"; import {} from "./dts.ts"; import type {} from "./dts.d.ts"; + +// @Filename: /c.ts +import {} from "./thisfiledoesnotexist.ts";