Skip to content

[TS2322] Component class with wider defaultProps typing #16

@alloy

Description

@alloy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    override candidate?Whether or not an issue should be solved with an override or in conversion or upstreamtype differenceAll about differences between Flow and TS typings (e.g. in React)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions