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

A syntax for function declarations to "implement" types (like const C: React.FC<Props> = (props0) => ...) #39039

Closed
5 tasks done
gfx opened this issue Jun 12, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@gfx
Copy link

gfx commented Jun 12, 2020

Search Terms

function,implements,type,interface

Suggestion

I'd like to make a function to implement types or interfaces. It is partially possible for variable declaration (e.g. const f: T = () => ...) but it is slightly different from what I'm issuing.

Use Cases & Examples

When making a React component.

It is a good practice to use React.FC<Props> when you make a React component like this:

import type React from "react";
type Props = { ... };
export const Foo: React.FC<Props> = (props) {
  ...
};

It's useful because a function component with a wrong return type doesn't compile. However, I think it's natural if I can declare implementing types for function declarations like this:

function Foo implements React.FC<Props> (props) {
  ...
}

(syntax doesn't matter; just for example)

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh
Copy link
Member

Duplicate #34319

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 12, 2020
@gfx
Copy link
Author

gfx commented Jun 14, 2020

Cool. A use-case for React.FC<Props> is also explained at #34319 (comment)

@gfx gfx closed this as completed Jun 14, 2020
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

2 participants