mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-30 18:43:21 +08:00
Merge pull request #21950 from jgoz/react-fragment-fix
[@types/react] Use ComponentType for React.Fragment
This commit is contained in:
15
types/react/index.d.ts
vendored
15
types/react/index.d.ts
vendored
@@ -88,7 +88,7 @@ declare namespace React {
|
||||
}
|
||||
|
||||
interface ReactElement<P> {
|
||||
type: string | symbol | number | ComponentClass<P> | SFC<P>;
|
||||
type: string | ComponentClass<P> | SFC<P>;
|
||||
props: P;
|
||||
key: Key | null;
|
||||
}
|
||||
@@ -222,7 +222,7 @@ declare namespace React {
|
||||
props?: ClassAttributes<T> & P,
|
||||
...children: ReactNode[]): CElement<P, T>;
|
||||
function createElement<P>(
|
||||
type: SFC<P> | ComponentClass<P> | string | symbol | number,
|
||||
type: SFC<P> | ComponentClass<P> | string,
|
||||
props?: Attributes & P,
|
||||
...children: ReactNode[]): ReactElement<P>;
|
||||
|
||||
@@ -265,7 +265,7 @@ declare namespace React {
|
||||
function isValidElement<P>(object: {} | null | undefined): object is ReactElement<P>;
|
||||
|
||||
const Children: ReactChildren;
|
||||
const Fragment: symbol | number;
|
||||
const Fragment: ComponentType;
|
||||
const version: string;
|
||||
|
||||
//
|
||||
@@ -281,10 +281,10 @@ declare namespace React {
|
||||
constructor(props: P, context?: any);
|
||||
|
||||
// Disabling unified-signatures to have separate overloads. It's easier to understand this way.
|
||||
// tslint:disable:unified-signatures
|
||||
// tslint:disable-next-line:unified-signatures
|
||||
setState<K extends keyof S>(f: (prevState: Readonly<S>, props: P) => Pick<S, K>, callback?: () => any): void;
|
||||
// tslint:disable-next-line:unified-signatures
|
||||
setState<K extends keyof S>(state: Pick<S, K>, callback?: () => any): void;
|
||||
// tslint:enable:unified-signatures
|
||||
|
||||
forceUpdate(callBack?: () => any): void;
|
||||
render(): ReactNode;
|
||||
@@ -3519,7 +3519,7 @@ declare namespace React {
|
||||
|
||||
declare global {
|
||||
namespace JSX {
|
||||
// tslint:disable:no-empty-interface
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface Element extends React.ReactElement<any> { }
|
||||
interface ElementClass extends React.Component<any> {
|
||||
render(): React.ReactNode;
|
||||
@@ -3527,9 +3527,10 @@ declare global {
|
||||
interface ElementAttributesProperty { props: {}; }
|
||||
interface ElementChildrenAttribute { children: {}; }
|
||||
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface IntrinsicAttributes extends React.Attributes { }
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface IntrinsicClassAttributes<T> extends React.ClassAttributes<T> { }
|
||||
// tslint:enable:no-empty-interface
|
||||
|
||||
interface IntrinsicElements {
|
||||
// HTML
|
||||
|
||||
@@ -164,7 +164,7 @@ const statelessElement: React.SFCElement<SCProps> = React.createElement(Stateles
|
||||
const domElement: React.DOMElement<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> = React.createElement("div");
|
||||
const htmlElement = React.createElement("input", { type: "text" });
|
||||
const svgElement = React.createElement("svg", { accentHeight: 12 });
|
||||
const fragmentElement: React.ReactElement<undefined> = React.createElement(React.Fragment, undefined, [React.createElement("div"), React.createElement("div")]);
|
||||
const fragmentElement: React.ReactElement<{}> = React.createElement(React.Fragment, {}, [React.createElement("div"), React.createElement("div")]);
|
||||
|
||||
const customProps: React.HTMLProps<HTMLElement> = props;
|
||||
const customDomElement = "my-element";
|
||||
@@ -229,7 +229,7 @@ const notValid: boolean = React.isValidElement(props); // false
|
||||
const isValid = React.isValidElement(element); // true
|
||||
let domNode: Element = ReactDOM.findDOMNode(component);
|
||||
domNode = ReactDOM.findDOMNode(domNode);
|
||||
const fragmentType: symbol | number = React.Fragment;
|
||||
const fragmentType: React.ComponentType = React.Fragment;
|
||||
|
||||
//
|
||||
// React Elements
|
||||
@@ -255,7 +255,7 @@ myComponent.reset();
|
||||
// Refs
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// tslint:disable:no-empty-interface
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface RCProps { }
|
||||
|
||||
class RefComponent extends React.Component<RCProps> {
|
||||
|
||||
@@ -63,3 +63,17 @@ const StatelessComponentWithoutProps: React.SFC = (props) => {
|
||||
return <div />;
|
||||
};
|
||||
<StatelessComponentWithoutProps />;
|
||||
|
||||
// Fragments
|
||||
<div>
|
||||
<React.Fragment>
|
||||
<React.Fragment key="foo">
|
||||
<span>Child 1</span>
|
||||
<span>Child 2</span>
|
||||
</React.Fragment>
|
||||
<React.Fragment key="bar">
|
||||
<span>Child 3</span>
|
||||
<span>Child 4</span>
|
||||
</React.Fragment>
|
||||
</React.Fragment>
|
||||
</div>;
|
||||
|
||||
Reference in New Issue
Block a user