Skip to content
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

Fix ts type generation #2038

Merged
merged 3 commits into from
Jun 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- run: pnpm types:check
- run: pnpm lint
- run: pnpm build
- run: pnpm test-typing
- run: pnpm test
env:
CI: true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ dist
.eslintcache
examples/**/yarn.lock
package-lock.json
tsconfig.tsbuildinfo
*/**/*.tsbuildinfo
coverage
*/**/.turbo
.turbo
.rollup.cache
4 changes: 3 additions & 1 deletion core/use-swr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
subscribeCallback,
getTimestamp,
internalMutate,
revalidateEvents,
revalidateEvents
} from 'swr/_internal'
import type {
State,
Fetcher,
Key,
Expand Down
3 changes: 2 additions & 1 deletion immutable/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import useSWR, { Middleware } from 'swr'
import type { Middleware } from 'swr'
import useSWR from 'swr'
import { withMiddleware } from 'swr/_internal'

export const immutable: Middleware = useSWRNext => (key, fetcher, config) => {
Expand Down
11 changes: 6 additions & 5 deletions infinite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ import {
isFunction,
UNDEFINED,
createCacheHelper,
useIsomorphicLayoutEffect,
serialize,
withMiddleware
} from 'swr/_internal'
import type {
BareFetcher,
SWRHook,
MutatorCallback,
Middleware,
BareFetcher,
useIsomorphicLayoutEffect,
serialize,
withMiddleware,
MutatorOptions
} from 'swr/_internal'

import type {
SWRInfiniteConfiguration,
SWRInfiniteResponse,
Expand Down
2 changes: 1 addition & 1 deletion mutation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Middleware,
Key
} from 'swr/_internal'
import {
import type {
SWRMutationConfiguration,
SWRMutationResponse,
SWRMutationHook,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"lint": "eslint . --ext .ts,.tsx --cache",
"lint:fix": "pnpm lint --fix",
"coverage": "jest --coverage",
"test": "tsc --noEmit -p test && jest"
"test-typing": "tsc --noEmit -p test/type/tsconfig.json && tsc --noEmit -p test/tsconfig.json",
"test": "jest"
},
"husky": {
"hooks": {
Expand Down
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
},
"include": [".", "./jest-setup.ts"],
// This file need "strict": true
"exclude": ["./type/mutator.ts"]
"exclude": ["./type"]
}
10 changes: 8 additions & 2 deletions test/type/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ export function useTestCache() {
}

export function useCustomSWRConfig() {
const noNull = [
// @ts-expect-error
<SWRConfig key={'null'} value={null} />,
// @ts-expect-error
<SWRConfig key={'callback-return-null'} value={() => null} />
]

return (
<>
<SWRConfig value={null} />
{noNull}
<SWRConfig value={undefined} />
<SWRConfig value={() => ({})} />
<SWRConfig value={() => null} />

<SWRConfig
// @ts-expect-error
Expand Down