mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
🤖 Merge PR #46643 [@types/react] add VoidFunctionComponent type which does not accept "children" by @awmottaz
Adds a type `VoidFunctionComponent` with `VFC` alias that is the same as the `FunctionComponent` (`FC`) type, except that it does not accept a `children` prop.
This commit is contained in:
parent
e606d5b467
commit
14d95eb0fe
10
types/react/index.d.ts
vendored
10
types/react/index.d.ts
vendored
@ -551,6 +551,16 @@ declare namespace React {
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
type VFC<P = {}> = VoidFunctionComponent<P>;
|
||||
|
||||
interface VoidFunctionComponent<P = {}> {
|
||||
(props: P, context?: any): ReactElement<any, any> | null;
|
||||
propTypes?: WeakValidationMap<P>;
|
||||
contextTypes?: ValidationMap<any>;
|
||||
defaultProps?: Partial<P>;
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
interface ForwardRefRenderFunction<T, P = {}> {
|
||||
(props: PropsWithChildren<P>, ref: ((instance: T | null) => void) | MutableRefObject<T | null> | null): ReactElement | null;
|
||||
displayName?: string;
|
||||
|
||||
@ -23,6 +23,25 @@ FunctionComponent2.defaultProps = {
|
||||
};
|
||||
<FunctionComponent2>24</FunctionComponent2>;
|
||||
|
||||
const VoidFunctionComponent: React.VoidFunctionComponent<SCProps> = ({ foo }: SCProps) => {
|
||||
return <div>{foo}</div>;
|
||||
};
|
||||
VoidFunctionComponent.displayName = "VoidFunctionComponent1";
|
||||
VoidFunctionComponent.defaultProps = {
|
||||
foo: 42
|
||||
};
|
||||
<VoidFunctionComponent />;
|
||||
|
||||
// $ExpectError
|
||||
const VoidFunctionComponent2: React.VoidFunctionComponent<SCProps> = ({ foo, children }) => {
|
||||
return <div>{foo}{children}</div>;
|
||||
};
|
||||
VoidFunctionComponent2.displayName = "VoidFunctionComponent2";
|
||||
VoidFunctionComponent2.defaultProps = {
|
||||
foo: 42
|
||||
};
|
||||
<VoidFunctionComponent2>24</VoidFunctionComponent2>; // $ExpectError
|
||||
|
||||
// svg sanity check
|
||||
<svg viewBox="0 0 1000 1000">
|
||||
<g>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user