-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pass serialized args to preload fetcher (#2564)
- Loading branch information
Showing
4 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { preload } from 'swr' | ||
import { expectType } from './utils' | ||
import type { Equal } from '@type-challenges/utils' | ||
|
||
export function testPreload() { | ||
const data1 = preload('key', () => Promise.resolve('value' as const)) | ||
expectType<Equal<Promise<'value'>, typeof data1>>(true) | ||
|
||
const data2 = preload( | ||
() => 'key', | ||
() => 'value' as const | ||
) | ||
expectType<Equal<'value', typeof data2>>(true) | ||
|
||
const data3 = preload<'value'>( | ||
() => 'key', | ||
() => 'value' as const | ||
) | ||
// specifing a generic param breaks the rest type inference so get FetcherResponse<"value"> | ||
expectType<Equal<'value' | Promise<'value'>, typeof data3>>(true) | ||
|
||
preload('key', key => { | ||
expectType<Equal<'key', typeof key>>(true) | ||
}) | ||
|
||
preload<'value'>( | ||
'key', | ||
( | ||
// @ts-expect-error -- infered any implicitly | ||
key | ||
) => { | ||
return 'value' as const | ||
} | ||
) | ||
|
||
preload(['key', 1], keys => { | ||
expectType<Equal<[string, number], typeof keys>>(true) | ||
}) | ||
|
||
preload( | ||
() => 'key' as const, | ||
key => { | ||
expectType<Equal<'key', typeof key>>(true) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters