Skip to content

Fix generix type declaration #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-async/src/Async.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ type AsyncConstructor<T> = React.ComponentClass<AsyncProps<T>> & {
* createInstance allows you to create instances of Async that are bound to a specific promise.
* A unique instance also uses its own React context for better nesting capability.
*/
export const createInstance = <T extends {}>(
export function createInstance<T>(
defaultOptions: AsyncProps<T> = {},
displayName = "Async"
): AsyncConstructor<T> => {
): AsyncConstructor<T> {
const { Consumer: UnguardedConsumer, Provider } = React.createContext<AsyncState<T> | undefined>(
undefined
)
Expand Down
13 changes: 5 additions & 8 deletions packages/react-async/src/useAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@ export interface FetchOptions<T> extends AsyncOptions<T> {
json?: boolean
}

function useAsync<T extends {}>(options: AsyncOptions<T>): AsyncState<T>
function useAsync<T extends {}>(promiseFn: PromiseFn<T>, options?: AsyncOptions<T>): AsyncState<T>
function useAsync<T>(options: AsyncOptions<T>): AsyncState<T>
function useAsync<T>(promiseFn: PromiseFn<T>, options?: AsyncOptions<T>): AsyncState<T>

function useAsync<T extends {}>(
arg1: AsyncOptions<T> | PromiseFn<T>,
arg2?: AsyncOptions<T>
): AsyncState<T> {
function useAsync<T>(arg1: AsyncOptions<T> | PromiseFn<T>, arg2?: AsyncOptions<T>): AsyncState<T> {
const options: AsyncOptions<T> =
typeof arg1 === "function"
? {
Expand Down Expand Up @@ -285,11 +282,11 @@ function isEvent(e: FetchRunArgs[0]): e is Event | React.SyntheticEvent {
* @param {FetchOptions} options
* @returns {AsyncState<T, FetchRun<T>>}
*/
const useAsyncFetch = <T extends {}>(
function useAsyncFetch<T>(
resource: RequestInfo,
init: RequestInit,
{ defer, json, ...options }: FetchOptions<T> = {}
): AsyncState<T, FetchRun<T>> => {
): AsyncState<T, FetchRun<T>> {
const method = (resource as Request).method || (init && init.method)
const headers: Headers & Record<string, any> =
(resource as Request).headers || (init && init.headers) || {}
Expand Down