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

Better support for import * from './foo.queries' #565

Open
SebastienGllmt opened this issue Jan 23, 2024 · 0 comments
Open

Better support for import * from './foo.queries' #565

SebastienGllmt opened this issue Jan 23, 2024 · 0 comments

Comments

@SebastienGllmt
Copy link

Is your feature request related to a problem? Please describe.

Ideally in the index.ts for my project I can just do

export * from './select.queries.js';
export * from './insert.queries.js';
export * from './update.queries.js';

However, this will fail if two or more of these files contain the same type definition. Notably, if for example both contain export type numberArray = (number)[]; then you will get the error

src/index.ts:3:1 - error TS2308: Module './select.queries.js' has already exported a member named 'numberArray'. Consider explicitly re-exporting to resolve the ambiguity.

Describe the solution you'd like

All extra type definitions created by pgtyped such as numberArray and other intermediary types (like enum types) should be places in a single common.ts (or a different name) and shared between all generated files. This doesn't introduce any performance overhead because these are all imported using import type which disappears at compile-time (and shouldn't negatively affect tree shaking either for the same reason).

Workaround

You can update your typesOverrides to alias common types to a common.ts manually:

"typesOverrides": {
    "lobby_status": "@src/common.js#LobbyStatus"
  }

This workaround does come with some unfortunate tradeoffs:

  1. It still requires you manually keep common.ts up-to-date if the SQL enum ever gets changed
  2. It makes that your project build output contains a @src import (see typesOverrides converts relative paths in possibly undesirable ways #564 for why)
  3. It won't work for types generated by pgtyped like numberArray that can't be aliased this way.
@SebastienGllmt SebastienGllmt changed the title Better support for import * from './foo.queries Better support for import * from './foo.queries' Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant