Skip to content

React TSX: Default Props Ignored with Index Signature #35092

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

Closed
chriszwickerocteris opened this issue Nov 13, 2019 · 4 comments
Closed

React TSX: Default Props Ignored with Index Signature #35092

chriszwickerocteris opened this issue Nov 13, 2019 · 4 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@chriszwickerocteris
Copy link

TypeScript Version:

  • 3.7.2
  • Nightly

Search Terms:
defaultprops index signature

Code

import * as React from "react";

export interface FooOptions {
  x: string;
  y?: string;
  [key: string]: any; // remove this and everything is ok
}

interface FooProps extends FooOptions {
  a: boolean;
}

class Foo extends React.Component<FooProps> {
  public static defaultProps = {
    a: true,
  };

  public render() {
    return <div>Remove index signature from FooOptions to make this work</div>
  }
}

class App extends React.Component {
  public render() {
    return (
      <Foo x={""} />
    );
  }
}

Expected behavior:
Default property recognized as present

Actual behavior:
Error that parameter a is missing: Property 'a' is missing in type '{ x: string; }' but required in type 'Readonly<FooProps>'

Playground Link:

Related Issues:

#23812

@weswigham
Copy link
Member

Interestingly, as I recently mentioned elsewhere, we don't actually implement any of the logic for checking defaultProps in the compiler - that's entirely in the domain of the react.d.ts over on DefinitelyTyped. I'd re-file this over there, where one of the .d.ts file maintainers can take a look at it.

@weswigham
Copy link
Member

Specifically, this is probably a known behavior for defaultProps types, but don't consider me the authority here, I'm just reading the source~

@chriszwickerocteris
Copy link
Author

Thanks for looking into it! I've opened DefinitelyTyped/DefinitelyTyped#40367

@andrewbranch andrewbranch added the External Relates to another program, environment, or user action which we cannot control. label Dec 10, 2019
@typescript-bot
Copy link
Collaborator

This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

4 participants