Annotating functions and classes with FunctionComponent
and ComponentClass
breaks LibraryManagedAttributes
due to the static defaultProps
property on those interfaces being set to optional.
import { FunctionComponent, ComponentClass, Component } from 'react' export interface Props { foo: string bar?: boolean } const TestFunction: FunctionComponent<Props> = props => <div /> TestFunction.defaultProps = { foo: '', } const TestClass: ComponentClass<Props> = class TestClass extends Component<Props> { static defaultProps = { foo: '', } render() { return <div /> } } // type is never type TestDefaultProps = typeof TestFunction extends { defaultProps: infer D } ? D : never type TestClassDefaultProps = typeof TestClass extends { defaultProps: infer D } ? D : never // type is Props because typeof Test does not extend { defaultProps } but rather { defaultProps? } type TestManagedProps = JSX.LibraryManagedAttributes<typeof TestFunction, Props> type TestClassManagedProps = JSX.LibraryManagedAttributes<typeof TestClass, Props>
This causes defaultProps
to be completely ignored by JSX.LibraryManagedAttributes
. We should probably remove it as a recommendation from the cheat sheet for now.
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