Skip to content

Commit 2488924

Browse files
authored
Merge pull request #229 from Khartir/fix-generic-type
Fix generix type declaration
2 parents 7d8544f + 129385c commit 2488924

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

packages/react-async/src/Async.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ type AsyncConstructor<T> = React.ComponentClass<AsyncProps<T>> & {
6868
* createInstance allows you to create instances of Async that are bound to a specific promise.
6969
* A unique instance also uses its own React context for better nesting capability.
7070
*/
71-
export const createInstance = <T extends {}>(
71+
export function createInstance<T>(
7272
defaultOptions: AsyncProps<T> = {},
7373
displayName = "Async"
74-
): AsyncConstructor<T> => {
74+
): AsyncConstructor<T> {
7575
const { Consumer: UnguardedConsumer, Provider } = React.createContext<AsyncState<T> | undefined>(
7676
undefined
7777
)

packages/react-async/src/useAsync.tsx

+5-8
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ export interface FetchOptions<T> extends AsyncOptions<T> {
3838
json?: boolean
3939
}
4040

41-
function useAsync<T extends {}>(options: AsyncOptions<T>): AsyncState<T>
42-
function useAsync<T extends {}>(promiseFn: PromiseFn<T>, options?: AsyncOptions<T>): AsyncState<T>
41+
function useAsync<T>(options: AsyncOptions<T>): AsyncState<T>
42+
function useAsync<T>(promiseFn: PromiseFn<T>, options?: AsyncOptions<T>): AsyncState<T>
4343

44-
function useAsync<T extends {}>(
45-
arg1: AsyncOptions<T> | PromiseFn<T>,
46-
arg2?: AsyncOptions<T>
47-
): AsyncState<T> {
44+
function useAsync<T>(arg1: AsyncOptions<T> | PromiseFn<T>, arg2?: AsyncOptions<T>): AsyncState<T> {
4845
const options: AsyncOptions<T> =
4946
typeof arg1 === "function"
5047
? {
@@ -285,11 +282,11 @@ function isEvent(e: FetchRunArgs[0]): e is Event | React.SyntheticEvent {
285282
* @param {FetchOptions} options
286283
* @returns {AsyncState<T, FetchRun<T>>}
287284
*/
288-
const useAsyncFetch = <T extends {}>(
285+
function useAsyncFetch<T>(
289286
resource: RequestInfo,
290287
init: RequestInit,
291288
{ defer, json, ...options }: FetchOptions<T> = {}
292-
): AsyncState<T, FetchRun<T>> => {
289+
): AsyncState<T, FetchRun<T>> {
293290
const method = (resource as Request).method || (init && init.method)
294291
const headers: Headers & Record<string, any> =
295292
(resource as Request).headers || (init && init.headers) || {}

0 commit comments

Comments
 (0)