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

[TS2322] Component class with wider defaultProps typing #16

Open
alloy opened this issue Jan 8, 2021 · 0 comments
Open

[TS2322] Component class with wider defaultProps typing #16

alloy opened this issue Jan 8, 2021 · 0 comments
Labels
override candidate? Whether or not an issue should be solved with an override or in conversion or upstream type difference All about differences between Flow and TS typings (e.g. in React)

Comments

@alloy
Copy link
Member

alloy commented Jan 8, 2021

There seem to be only a few of these, one is here. Perhaps best to solve with an override.

import * as React from "react"

class Foo extends React.Component<{ mode?: null | undefined | ("dialog" | "dropdown") }> {
  static defaultProps: {
    // This supertype here makes it no longer match the React.ComponentClass interface,
    // which is used in React.ComponentType
    mode: string
    // This works
    // mode?: null | undefined | ("dialog" | "dropdown")
  }
}

type ExtractProps<X> = X extends React.ComponentType<infer P> ? P : never

type Props = ExtractProps<typeof Foo>
const props: Props = { mode: "dialog" }

React.ComponentClass is defined here.

@alloy alloy added type difference All about differences between Flow and TS typings (e.g. in React) override candidate? Whether or not an issue should be solved with an override or in conversion or upstream labels Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
override candidate? Whether or not an issue should be solved with an override or in conversion or upstream type difference All about differences between Flow and TS typings (e.g. in React)
Projects
None yet
Development

No branches or pull requests

1 participant