From my understanding, import type should only introduce a symbol in the type namespace, while import * as X should introduce a symbol in the value namespace, so I would expect both to coexist. But I’m hitting a Duplicate identifier error in TypeScript.
Minimal reproducible example:
// moduleX.ts
export type X = (value: T) => T
export const map =
(f: (x: T) => T) =>
(x: X): X =>
v => f(x(v))
Usage:
import type { X } from "./moduleX"
import * as X from "./moduleX"
Compiler error:
Duplicate identifier 'X'
Additional observations:
Each import compiles correctly when used alone
The error only occurs when both imports are present
Compilation is done using
tsc(no Babel, SWC, or other transpilers)
Questions
Why does a namespace import (
import * as X) conflict with a type-only import of the same name?Does
import * as Xintroduce a symbol into the type space in addition to the value space?Is there any compiler option that allows these two imports to coexist without renaming, or is aliasing the type the intended and only solution?