A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/DefinitelyTyped/DefinitelyTyped/issues/30695 below:

defaultProps doesn't work when FunctionalComponent<P> is used · Issue #30695 · DefinitelyTyped/DefinitelyTyped · GitHub

Dependencies:

"typescript": "3.2.0-rc"
"@types/react": "16.7.6",
"@types/react-dom": "16.0.9",

As stated by @Kovensky

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/test/managedAttributes.tsx#L167-L175

defaultProps doesn't properly apply on JSX tag when function component is defined via FunctionalComponent

Code:

import React, { FunctionComponent } from 'react'

type Props = {
  onClick: (ev: import('react').MouseEvent<HTMLElement>) => void
  children: import('react').ReactChild
  color: 'red' | 'green'
}

const Button: FunctionComponent<Props> = ({ onClick: handleClick, color, children }) => (
  <button style={{ color }} onClick={handleClick}>
    {children}
  </button>
)
Button.defaultProps = {
  color: 'red'
}

const Test = () => (
  <>
     /* $ExpectError */
    <Button onClick={() => console.log('clicked')}>Click me</Button>
  </>
)

Related:
#29816
microsoft/TypeScript#27425

cloudlena, evgenymarkov, michalkvasnicak, pret-a-porter, leoyli and 6 more


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4