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

Suggestion: Allow named functions to use predefined types #19106

Closed
matthew-gerstman opened this issue Oct 11, 2017 · 5 comments
Closed

Suggestion: Allow named functions to use predefined types #19106

matthew-gerstman opened this issue Oct 11, 2017 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@matthew-gerstman
Copy link

Currently there is no way to use a predefined type with a named function in typescript. I find this regularly causes issues with functional stateless components in React.

function NamedComponent() {
  return <div />;
}
// [ts] Property 'propTypes' does not exist on type '() => Element'.
NamedComponent.propTypes = {};

const ConstComponent: React.SFC<{}> = () => {
  return <div />;
};
ConstComponent.propTypes = {};

I'm propose a method to type traditionally named functions.

Grammar Options

Option 1

function: React.SFC<{}>  NamedComponent() {
  return <div />;
}

Option 2

function NamedComponent: React.SFC<{}> () {
  return <div />;
}
@ghost
Copy link

ghost commented Oct 11, 2017

You can do this:

function NamedComponent() {
}
namespace NamedComponent {
    export const propTypes = {};
}

Unfortunately, we won't do any excess property checking in this case. Although if you could write function: React.SFC and React.SFC had some required properties, I'm not sure how we could enforce them to be assigned.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 11, 2017

Duplicate of #15868

@mhegazy mhegazy marked this as a duplicate of #15868 Oct 11, 2017
@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 11, 2017
@Jessidhia
Copy link

More accurately this is a duplicate of #16918

@matthew-gerstman
Copy link
Author

Thanks guys! I searched for previous issues but apparently my skills failed me 😅 . I think @Kovensky is right, #16918 is what I'm looking for.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 26, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Oct 26, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants