Export auto-scan does not scan (untranspiled) TypeScript packages correctly
Opened this issue · 0 comments
andrew8088 commented
Environment
Node v21.6.2
typescript@5.4.2
unimport@3.7.1
vite@5.1.6
Reproduction
- clone this repro repo: https://github.com/andrew8088/unimport-ts-bug-repro
cd
into repopnpm i
cd packages/app
- If you want to regenerate the type definition file:
rm unimport.d.ts
pnpm dev
- kill the dev server
- Now,
pnpm build
- you should see several
Property '...' does not exist on type ...
errors fromtsc
.
- you should see several
Describe the bug
The package we're auto-importing has these functions:
export function function1<A, B = string>(a: A, b: B) {
return [a, b];
}
export function function2<C, D>(c: C, d: D) {
return [c, d];
}
export function function3<E>(e: E, f: E) {
return [e, f];
}
type F = number;
export function function4(g: F, h: F) {
return [g, h];
}
The generated unimport.d.ts
file looks like this:
export {}
declare global {
const B: typeof import('common')['B']
const D: typeof import('common')['D']
const b: typeof import('common')['b']
const d: typeof import('common')['d']
const f: typeof import('common')['f']
const function1: typeof import('common')['function1']
const function2: typeof import('common')['function2']
const function3: typeof import('common')['function3']
const function4: typeof import('common')['function4']
const h: typeof import('common')['h']
}
All the exports that are not function*
are not actually exported from the package. Looks like this is actually coming from the mlly
package, which is expecting to import JS only.
Not sure if this is a bug or not. I'd like to be able to treat other packages within my monorepo as packages (and auto-import them via presets
), and not use the dirs
option to import them.
Additional context
No response
Logs
$ pnpm tsc
unimport.d.ts:3:36 - error TS2339: Property 'B' does not exist on type 'typeof import("/Users/andrew/code/projects/disco/packages/common/index")'.
3 const B: typeof import('common')['B']
~~~
unimport.d.ts:4:36 - error TS2339: Property 'D' does not exist on type 'typeof import("/Users/andrew/code/projects/disco/packages/common/index")'.
4 const D: typeof import('common')['D']
~~~
unimport.d.ts:5:36 - error TS2339: Property 'b' does not exist on type 'typeof import("/Users/andrew/code/projects/disco/packages/common/index")'.
5 const b: typeof import('common')['b']
~~~
unimport.d.ts:6:36 - error TS2339: Property 'd' does not exist on type 'typeof import("/Users/andrew/code/projects/disco/packages/common/index")'.
6 const d: typeof import('common')['d']
~~~
unimport.d.ts:7:36 - error TS2339: Property 'f' does not exist on type 'typeof import("/Users/andrew/code/projects/disco/packages/common/index")'.
7 const f: typeof import('common')['f']
~~~
unimport.d.ts:12:36 - error TS2339: Property 'h' does not exist on type 'typeof import("/Users/andrew/code/projects/disco/packages/common/index")'.
12 const h: typeof import('common')['h']
~~~
Found 6 errors in the same file, starting at: unimport.d.ts:3