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

VoidFunction interface should be defined for ES5 target #61009

Closed
galkin opened this issue Jan 22, 2025 · 5 comments
Closed

VoidFunction interface should be defined for ES5 target #61009

galkin opened this issue Jan 22, 2025 · 5 comments

Comments

@galkin
Copy link

galkin commented Jan 22, 2025

⚙ Compilation target

ES5

⚙ Library

lib.es5.d.ts

Missing / Incorrect Definition

In lib.dom.d.ts and similar files produced by TypeScript-DOM-lib-generator we have:

interface VoidFunction {
    (): void;
}

This interface is commonly used for frontend development, but it is not defined with recommended Node.js configuration

Adding this interface to lib.es5.d.ts will simplify FullStack practices

Sample Code

type props = {
  handle: voidFunction;
}

Documentation Link

No response

@galkin
Copy link
Author

galkin commented Jan 22, 2025

@sandersn, could you provide your opinion about this tiny issue? I linked a fix.
I don't think we need any changes in TypeScript-DOM-lib-generator, but adding to es5 will also provide Node.js dev use the interface.

@jakebailey
Copy link
Member

We don't add helper types they're required for dts emit; I don't think we would add this.

@galkin
Copy link
Author

galkin commented Jan 22, 2025

@jakebailey, helper types like those in dom.lib have been widely used by the TypeScript community.

However, Node.js developers face a challenge since dom.lib isn’t used, and we often need to recreate these helpers in every project. What does the TypeScript team recommend to address this?

  1. Should we propose moving or adding these helpers from dom to es5?
  2. Should we add them to @types/node?
  3. Or, should we create a new package for these helpers and promote it?

For now, I’ve only identified VoidFunction, but there might be others. I’d appreciate your guidance!

@jakebailey
Copy link
Member

helper types like those in dom.lib have been widely used by the TypeScript community.

Being widely used does not mean we add them for everyone.

Notably, https://github.com/search?q=%2F%5CbVoidFunction%5Cb%2F+language%3ATypeScript&type=code shows that most uses of this name are people declaring the type, not using the one from the DOM types.

To your three questions, my personal opinion is "no" for all three. This is a one line type; most people would not declare type VoidFunction = () => void, when they can just type () => void directly, which is shorter and clearer.

@galkin
Copy link
Author

galkin commented Jan 22, 2025

it makes sense. I'm closing the issue and the PR. Thanks for your time!

@galkin galkin closed this as completed Jan 22, 2025
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.

2 participants