Remove always-incorrect error message about importing .ts extensions (#52595)

This commit is contained in:
Andrew Branch 2023-02-03 15:02:57 -08:00 коммит произвёл GitHub
Родитель ddadea1732
Коммит 2e9da1e5a1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
10 изменённых файлов: 180 добавлений и 31 удалений

Просмотреть файл

@ -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);
/**

Просмотреть файл

@ -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

Просмотреть файл

@ -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.

Просмотреть файл

@ -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?

Просмотреть файл

@ -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.

Просмотреть файл

@ -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.

Просмотреть файл

@ -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.

Просмотреть файл

@ -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;

Просмотреть файл

@ -1029,7 +1029,6 @@ Info 32 [00:01:13.000] response:
"2685",
"2687",
"2688",
"2691",
"2692",
"2694",
"2695",

Просмотреть файл

@ -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";