mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
isolatedModules error on alias merging with local value (#56354)
This commit is contained in:
parent
e40730f283
commit
a6367977d4
@ -45427,6 +45427,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
|
||||
error(node, message, symbolToString(symbol));
|
||||
}
|
||||
else if (node.kind !== SyntaxKind.ExportSpecifier) {
|
||||
// Look at 'compilerOptions.isolatedModules' and not 'getIsolatedModules(...)' (which considers 'verbatimModuleSyntax')
|
||||
// here because 'verbatimModuleSyntax' will already have an error for importing a type without 'import type'.
|
||||
const appearsValueyToTranspiler = compilerOptions.isolatedModules && !findAncestor(node, isTypeOnlyImportOrExportDeclaration);
|
||||
if (appearsValueyToTranspiler && symbol.flags & (SymbolFlags.Value | SymbolFlags.ExportValue)) {
|
||||
error(
|
||||
node,
|
||||
Diagnostics.Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled,
|
||||
symbolToString(symbol),
|
||||
isolatedModulesLikeFlagName,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
getIsolatedModules(compilerOptions)
|
||||
|
||||
@ -3711,6 +3711,10 @@
|
||||
"category": "Error",
|
||||
"code": 2864
|
||||
},
|
||||
"Import '{0}' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.": {
|
||||
"category": "Error",
|
||||
"code": 2865
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
@ -140,6 +140,7 @@ class CompilerTest {
|
||||
"importHelpers",
|
||||
"downlevelIteration",
|
||||
"isolatedModules",
|
||||
"verbatimModuleSyntax",
|
||||
"strict",
|
||||
"noImplicitAny",
|
||||
"strictNullChecks",
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
bad.ts(1,10): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
|
||||
bad.ts(1,10): error TS1484: 'FC' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
|
||||
|
||||
|
||||
==== types.ts (0 errors) ====
|
||||
export type FC = () => void;
|
||||
|
||||
==== bad.ts (2 errors) ====
|
||||
import { FC } from "./types";
|
||||
~~
|
||||
!!! error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
|
||||
~~
|
||||
!!! error TS1484: 'FC' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
|
||||
let FC: FC | null = null;
|
||||
|
||||
==== good.ts (0 errors) ====
|
||||
import type { FC } from "./types";
|
||||
let FC: FC | null = null;
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
bad.ts(1,10): error TS2865: Import 'FC' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.
|
||||
|
||||
|
||||
==== types.ts (0 errors) ====
|
||||
export type FC = () => void;
|
||||
|
||||
==== bad.ts (1 errors) ====
|
||||
import { FC } from "./types";
|
||||
~~
|
||||
!!! error TS2865: Import 'FC' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.
|
||||
let FC: FC | null = null;
|
||||
|
||||
==== good.ts (0 errors) ====
|
||||
import type { FC } from "./types";
|
||||
let FC: FC | null = null;
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
bad.ts(1,10): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
|
||||
bad.ts(1,10): error TS1484: 'FC' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
|
||||
bad.ts(1,10): error TS2865: Import 'FC' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.
|
||||
|
||||
|
||||
==== types.ts (0 errors) ====
|
||||
export type FC = () => void;
|
||||
|
||||
==== bad.ts (3 errors) ====
|
||||
import { FC } from "./types";
|
||||
~~
|
||||
!!! error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
|
||||
~~
|
||||
!!! error TS1484: 'FC' is a type and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled.
|
||||
~~
|
||||
!!! error TS2865: Import 'FC' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.
|
||||
let FC: FC | null = null;
|
||||
|
||||
==== good.ts (0 errors) ====
|
||||
import type { FC } from "./types";
|
||||
let FC: FC | null = null;
|
||||
|
||||
@ -0,0 +1,15 @@
|
||||
// @isolatedModules: false, true
|
||||
// @verbatimModuleSyntax: false, true
|
||||
// @noEmit: true
|
||||
// @noTypesAndSymbols: true
|
||||
|
||||
// @Filename: types.ts
|
||||
export type FC = () => void;
|
||||
|
||||
// @Filename: bad.ts
|
||||
import { FC } from "./types";
|
||||
let FC: FC | null = null;
|
||||
|
||||
// @Filename: good.ts
|
||||
import type { FC } from "./types";
|
||||
let FC: FC | null = null;
|
||||
Loading…
x
Reference in New Issue
Block a user