Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export auto-scan does not scan (untranspiled) TypeScript packages correctly #332

Open
andrew8088 opened this issue Mar 24, 2024 · 0 comments

Comments

@andrew8088
Copy link

andrew8088 commented Mar 24, 2024

Environment

Node v21.6.2
typescript@5.4.2
unimport@3.7.1
vite@5.1.6

Reproduction

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
@andrew8088 andrew8088 changed the title Export auto-scan bug: function arguments and types incorrect become their own exports Export auto-scan TypeScript bug: function arguments and types incorrect become their own exports Mar 24, 2024
@andrew8088 andrew8088 changed the title Export auto-scan TypeScript bug: function arguments and types incorrect become their own exports Export auto-scan does not scan (untranspiled) TypeScript packages correctly Mar 25, 2024
andrew8088 added a commit to andrew8088/unimport that referenced this issue Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant