You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Name overload term/type module re-export as namespaceΒ #51109
I want to be able to reuse a name for a type and namespace for more streamlined downstream usage.
π» Use Cases
All the same use-cases there already are today for namespace name overloading between terms/types.
Reacted by Sam A. Horvath-Hunt, Conner Ruhl, Scott Moore, danieljaegers, grapedge, Patrick Roza, Wayne Maurer, Federico Biccheddu, David Blass, Janusz DziurzyΕski and 2 more
An update: the example in this issue compiles now. Since #50853 (TypeScript 4.9; see #36792), a type alias merges with a namespace re-export of the same name:
What still fails is the type-only re-export spelling of the same thing:
// Commit.tsexporttypeCommit={readonlysha: string}exportconstmake=(sha: string): Commit=>({ sha })// door.tsexport*asCommitfrom'./Commit.js'// TS2300: Duplicate identifier 'Commit'.exporttype{Commit}from'./Commit.js'// TS2300: Duplicate identifier 'Commit'.// use.tsimport*asDoorfrom'./door.js'exportconstcommit: Door.Commit=Door.Commit.make('x')// TS2749: 'Door.Commit' refers to a value, but is being used as a type here.
Checked with TypeScript 7.1.0-beta and 7.0.0-dev.20260707.2 (module/moduleResolutionNodeNext, strict).
Both lines in door.ts declare an alias named Commit, and an alias excludes every other alias of the same name (SymbolFlagsAliasExcludes = SymbolFlagsAlias, typescript-go internal/ast/symbolflags.go). So the import() type alias is the only spelling that works today, and a codebase that bans inline import() types (for example @typescript-eslint/consistent-type-imports with disallowTypeAnnotations: true) has to exempt every file that uses this pattern.
Activity
MartinJohns commentedon Oct 8, 2022
I believe this to be a duplicate of #48764 (comment).
jasonkuhrt commentedon Oct 8, 2022
Thanks Martin Johns (@MartinJohns). That issue was about the
typeimport while mine is a suggestion that it should work like namespaces.That issue was/is closed with the counter-example of importing a class.
What I'm saying here wouldn't be closed because of that counter example.
I'm merely saying it works with
namespaceand ought to work with native ESM modules now that we have them.cruhl commentedon Oct 25, 2022
I have been trying to get something like this working for literal years now.
It would dramatically help write better functional/Rust-module-style code.
cruhl commentedon Oct 25, 2022
Jason Kuhrt (@jasonkuhrt) check out this related issue/discussion:
#39865
cruhl commentedon Oct 25, 2022
Another relevant discussion...
#48764 (comment)
cruhl commentedon Oct 25, 2022
Good overview of the resulting friction this would alleviate here:
#48764 (comment)
cruhl commentedon Oct 25, 2022
Here's a good example of the awkwardness this causes for users of Giulio Canti (@gcanti)'s fp-ts...
gcanti/fp-ts#1633
cruhl commentedon Oct 25, 2022
Here is my dream syntax...
import * as User, type { User } from "./User";cruhl commentedon Oct 25, 2022
gcanti/fp-ts#1415

cruhl commentedon Oct 25, 2022
This problem won't be going away anytime soon, so I would expect it to continually pop up so long as issues keep getting closed...
cruhl commentedon Oct 25, 2022
Oddly, this halfway works, but fails to see
export * as Point from "./Point";correctly...'Point' only refers to a type, but is being used as a value here.ts(2693)cruhl commentedon Oct 25, 2022
So this actually works...



cruhl commentedon Oct 27, 2022
So this actually works...
jasonkuhrt commentedon Nov 3, 2026
An update: the example in this issue compiles now. Since #50853 (TypeScript 4.9; see #36792), a type alias merges with a namespace re-export of the same name:
What still fails is the type-only re-export spelling of the same thing:
Checked with TypeScript 7.1.0-beta and 7.0.0-dev.20260707.2 (
module/moduleResolutionNodeNext,strict).Both lines in
door.tsdeclare an alias namedCommit, and an alias excludes every other alias of the same name (SymbolFlagsAliasExcludes = SymbolFlagsAlias, typescript-gointernal/ast/symbolflags.go). So theimport()type alias is the only spelling that works today, and a codebase that bans inlineimport()types (for example@typescript-eslint/consistent-type-importswithdisallowTypeAnnotations: true) has to exempt every file that uses this pattern.