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

function() implements () => unknown {} #52902

Closed
5 tasks done
DanieliusDev opened this issue Feb 21, 2023 · 3 comments
Closed
5 tasks done

function() implements () => unknown {} #52902

DanieliusDev opened this issue Feb 21, 2023 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@DanieliusDev
Copy link

DanieliusDev commented Feb 21, 2023

Suggestion

πŸ” Search Terms

function implements

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Allow to add a implements Type for a function (not arrow functions). This would allow to easily use a function type on a non-arrow function.

πŸ“ƒ Motivating Example

export default function Component(props) implements React.FC {
    // ...
}

πŸ’» Use Cases

Usually whenever we want to use a function type from a library such as react, we tend to do one of the two things:

  • add the argument and return types ourselves
  • create a new variable for a function with most likely an arrow function

This isn't awful to have to deal with but most people prefer using function instead of arrow functions whenever declaring a function which is not a call-back for a function. Another problem is that we can't type a function whenever using export.

Here is how we currently make and export a function:

const Component: React.FC = (props) => {
    // ...
}

export default Component;

or

export default function Component(props: {}): React.ReactElement<any, any> {
    // ...
}

Here is how it could be done:

export default function Component(props) implements React.FC {
    // ...
}
@IllusionMH
Copy link
Contributor

Duplicate of #22063 and other similar proposals

@DanieliusDev
Copy link
Author

Duplicate of #22063 and other similar proposals

5 years ago and still no implementation....

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 22, 2023
@RyanCavanaugh
Copy link
Member

Wait until you hear how long there have been feature suggestions in C++!

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants