egoist / egoist/tsup

`import type { X as Y } from "@package";` - Import alias doesn't get build properly and get lost

Open
#1,179 2 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

I'm expecting `tsup` & `dts` to not change my alias declarations name like `import type { X as Y } from "@package";` but it seems like it does indeed remove them. Leading to problem in build types. Is this expected ?

Explanations:
[Codesandbox](https://codesandbox.io/p/devbox/tsup-dual-example-forked-kglylh)

1. I'm declaring my `types` namespace in `src/test.ts`.
**Info:** I'm importing my external package like so `import type { PartialDeep as PartialDeepPrimitive } from "type-fest";`

2. It compiles in `dist/esm/test.d.ts`.
**Info:** The import get transformed to `import { PartialDeep } from 'type-fest';` and thus exporting that way in my namespace: `type PartialDeep = PartialDeep;` which is a problem I'm assuming - it seems like it produces a sort of type loop.

3. When using the builded files in `src/index.ts`, `types.PartialDeep` logically resolves to any.

Can someone explain why it does this and if I can fix this quickly with a param or if this is just an actual issue ?

Thanks :)

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the linked CodeSandbox, then compare src/test.ts with the generated dist/esm/test.d.ts and the consuming src/index.ts. Trace declaration generation for the aliased type-fest import; done means the alias remains valid in the built declaration and types.PartialDeep resolves correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.