Skip to content

Commit dc9ebf9

Browse files
committed
Use JSX.Element instead of ReactNode in types. Fixed with-typescript
example.
1 parent d152d49 commit dc9ebf9

File tree

5 files changed

+24
-36
lines changed

5 files changed

+24
-36
lines changed

Diff for: examples/basic-fetch/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"version": "0.0.0",
44
"private": true,
55
"dependencies": {
6-
"react": "^16.8.5",
6+
"react": "^16.8.6",
77
"react-async": "latest",
8-
"react-dom": "^16.8.5",
9-
"react-scripts": "2.1.8"
8+
"react-dom": "^16.8.6",
9+
"react-scripts": "^3.0.1"
1010
},
1111
"scripts": {
1212
"start": "react-scripts start",

Diff for: examples/with-typescript/.env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SKIP_PREFLIGHT_CHECK=true

Diff for: examples/with-typescript/package.json

+8-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6-
"@types/jest": "24.0.11",
7-
"@types/node": "11.11.7",
8-
"@types/react": "16.8.8",
9-
"@types/react-dom": "16.8.3",
10-
"react": "16.8.5",
11-
"react-async": "5.1.2",
12-
"react-dom": "16.8.5",
13-
"react-scripts": "2.1.8",
14-
"typescript": "3.3.4000"
6+
"@types/node": "^12.0.8",
7+
"@types/react": "^16.8.19",
8+
"@types/react-dom": "^16.8.4",
9+
"react": "^16.8.6",
10+
"react-async": "latest",
11+
"react-dom": "^16.8.6",
12+
"react-scripts": "^3.0.1",
13+
"typescript": "^3.5.1"
1514
},
1615
"scripts": {
1716
"start": "react-scripts start",

Diff for: examples/with-typescript/src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class App extends Component {
77
return (
88
<div className="App">
99
<header className="App-header">
10-
<Async promiseFn={() => Promise.resolve("foo")}>{({ data }: { data: string }) => data}</Async>
10+
<Async promiseFn={() => Promise.resolve("foo")}>{({ data }) => <>{data}</>}</Async>
1111
<Async promiseFn={() => Promise.resolve("bar")}>
12-
<Async.Pending>{(data: string) => data}</Async.Pending>
12+
<Async.Resolved>{data => <>{data}</>}</Async.Resolved>
1313
</Async>
1414
</header>
1515
</div>

Diff for: src/index.d.ts

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as React from "react"
1+
import { Component } from "react"
22

3-
export type AsyncChildren<T> = ((state: AsyncState<T>) => React.ReactNode) | React.ReactNode
3+
export type AsyncChildren<T> = ((state: AsyncState<T>) => JSX.Element) | JSX.Element
44
export type PromiseFn<T> = (props: object, controller: AbortController) => Promise<T>
55
export type DeferFn<T> = (args: any[], props: object, controller: AbortController) => Promise<T>
66

@@ -113,37 +113,25 @@ export type AsyncRejected<T> = AbstractState<T> & {
113113
}
114114
export type AsyncState<T> = AsyncInitial<T> | AsyncPending<T> | AsyncFulfilled<T> | AsyncRejected<T>
115115

116-
declare class Async<T> extends React.Component<AsyncProps<T>, AsyncState<T>> {}
116+
declare class Async<T> extends Component<AsyncProps<T>, AsyncState<T>> {}
117117

118118
declare namespace Async {
119-
export function Initial<T>(props: {
120-
children?: AsyncChildren<T>
121-
persist?: boolean
122-
}): React.ReactNode
123-
export function Pending<T>(props: {
124-
children?: AsyncChildren<T>
125-
initial?: boolean
126-
}): React.ReactNode
127-
export function Loading<T>(props: {
128-
children?: AsyncChildren<T>
129-
initial?: boolean
130-
}): React.ReactNode
119+
export function Initial<T>(props: { children?: AsyncChildren<T>; persist?: boolean }): JSX.Element
120+
export function Pending<T>(props: { children?: AsyncChildren<T>; initial?: boolean }): JSX.Element
121+
export function Loading<T>(props: { children?: AsyncChildren<T>; initial?: boolean }): JSX.Element
131122
export function Fulfilled<T>(props: {
132123
children?: AsyncChildren<T>
133124
persist?: boolean
134-
}): React.ReactNode
125+
}): JSX.Element
135126
export function Resolved<T>(props: {
136127
children?: AsyncChildren<T>
137128
persist?: boolean
138-
}): React.ReactNode
129+
}): JSX.Element
139130
export function Rejected<T>(props: {
140131
children?: AsyncChildren<T>
141132
persist?: boolean
142-
}): React.ReactNode
143-
export function Settled<T>(props: {
144-
children?: AsyncChildren<T>
145-
persist?: boolean
146-
}): React.ReactNode
133+
}): JSX.Element
134+
export function Settled<T>(props: { children?: AsyncChildren<T>; persist?: boolean }): JSX.Element
147135
}
148136

149137
export function createInstance<T>(defaultProps?: AsyncProps<T>): Async<T>

0 commit comments

Comments
 (0)