-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
Proposal: GlobalConstructor
#249
Comments
What does the code for |
I’m not sure what it should look like. I can think of specific implementations, but not of a reusable one as I proposed here. Perhaps it’s better to just expose some types with quirky behaviour between NodeJS and the dom lib. // Buffer if @types/node is included
// never if @types/node is not included
export type Buffer = typeof globalThis extends {Buffer: {from: (string: any) => infer T}} ? T : never Unfortunately if this is processed by TypeScript when generating a |
Currently this module has no types which interacts with the global types in any way. The I think this is best handled in a similar way, keeping this module's focus strictly on utility types in the spirit of https://www.typescriptlang.org/docs/handbook/utility-types.html |
I agree with @voxpelli. I also think it's a problem the TypeScript project should fix. I would recommend opening an issue there about it: https://github.com/microsoft/TypeScript |
Sometimes it’s useful to get a property which may or may not exist on a type.
A practical example is that many libraries support both NodeJS buffers and a browser environment. If these libraries depend on the
Buffer
type, they need to pull in@types/node
. However, this is undesirable for a browser environment. This helper type could resolve the issue like this:The text was updated successfully, but these errors were encountered: