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

Add common types to their own file/export w/outputIndex option #1015

Open
Tofandel opened this issue Mar 19, 2024 · 2 comments
Open

Add common types to their own file/export w/outputIndex option #1015

Tofandel opened this issue Mar 19, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Tofandel
Copy link

In each ts file generated there is

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
  : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
  : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
  : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
  : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

function isSet(value: any): boolean {
  return value !== null && value !== undefined;
}

The biggest problem I have with this is that they are exported (so I can't use export * from './protofile.ts')

Is there a way to have them imported from a shared file in each ts file and to not export them?

@Tofandel
Copy link
Author

https://github.com/stephenh/ts-proto/pull/821/files

Seems there is an exportCommonSymbols option which solves the problem at hand, but I will leave open for the other improvement which is to output those types in a separate file and import them

@Tofandel Tofandel changed the title Is there a way to avoid exporting of reused types Is there a way to reuse common types? Mar 19, 2024
@stephenh
Copy link
Owner

Hi @Tofandel , you're right we don't have an option to put the common types in a shared package, and export that from the index file. We could probably just do that if outputIndex=true was enabled.

If you'd like to submit a PR for that, that'd be great! Thank you!

@stephenh stephenh changed the title Is there a way to reuse common types? Add common types to their own file/export w/outputIndex option Mar 21, 2024
@stephenh stephenh added enhancement New feature or request help wanted Extra attention is needed labels Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants