forked from TanStack/query
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add typescript support (TanStack#767)
- Loading branch information
Showing
58 changed files
with
3,119 additions
and
1,724 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": ["react-app", "prettier"], | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint"], | ||
"extends": [ | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"react-app", | ||
"prettier" | ||
], | ||
"env": { | ||
"es6": true | ||
}, | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/no-empty-interface": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -27,3 +27,6 @@ yarn-error.log* | |
size-plugin.json | ||
stats.html | ||
.vscode/settings.json | ||
|
||
!/types/index.d.ts | ||
types/**/*.ts |
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,24 @@ | ||
--- | ||
id: typescript | ||
title: TypeScript | ||
--- | ||
|
||
React Query is now written in **TypeScript** to make sure the library and your projects are type-safe! | ||
|
||
## Migration | ||
|
||
React Query is currently typed with an external type definition file, which unfortunately often gets out of sync with the actual code. | ||
|
||
This is one of the reasons why the library has been migrated to TypeScript. | ||
|
||
But before exposing the new types, we first want to get your feedback on it! | ||
|
||
Install the `tsnext` tag to get the latest React Query with the new types: | ||
|
||
```sh | ||
npm install react-query@tsnext --save | ||
``` | ||
|
||
## Changes | ||
|
||
- The query results are no longer discriminated unions, which means you have to check the actual `data` and `error` properties. |
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 was deleted.
Oops, something went wrong.
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,58 @@ | ||
import { stableStringify, identity, deepEqual } from './utils' | ||
import { | ||
ArrayQueryKey, | ||
QueryKey, | ||
QueryKeySerializerFunction, | ||
ReactQueryConfig, | ||
} from './types' | ||
|
||
// TYPES | ||
|
||
export interface ReactQueryConfigRef { | ||
current: ReactQueryConfig | ||
} | ||
|
||
// CONFIG | ||
|
||
export const defaultQueryKeySerializerFn: QueryKeySerializerFunction = ( | ||
queryKey: QueryKey | ||
): [string, ArrayQueryKey] => { | ||
try { | ||
let arrayQueryKey: ArrayQueryKey = Array.isArray(queryKey) | ||
? queryKey | ||
: [queryKey] | ||
const queryHash = stableStringify(arrayQueryKey) | ||
arrayQueryKey = JSON.parse(queryHash) | ||
return [queryHash, arrayQueryKey] | ||
} catch { | ||
throw new Error('A valid query key is required!') | ||
} | ||
} | ||
|
||
export const DEFAULT_CONFIG: ReactQueryConfig = { | ||
shared: { | ||
suspense: false, | ||
}, | ||
queries: { | ||
queryKeySerializerFn: defaultQueryKeySerializerFn, | ||
enabled: true, | ||
retry: 3, | ||
retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, 30000), | ||
staleTime: 0, | ||
cacheTime: 5 * 60 * 1000, | ||
refetchOnWindowFocus: true, | ||
refetchInterval: false, | ||
queryFnParamsFilter: identity, | ||
refetchOnMount: true, | ||
isDataEqual: deepEqual, | ||
useErrorBoundary: false, | ||
}, | ||
mutations: { | ||
throwOnError: false, | ||
useErrorBoundary: false, | ||
}, | ||
} | ||
|
||
export const defaultConfigRef: ReactQueryConfigRef = { | ||
current: DEFAULT_CONFIG, | ||
} |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
export { queryCache, queryCaches, makeQueryCache } from './queryCache' | ||
export { setFocusHandler } from './setFocusHandler' | ||
export { stableStringify, setConsole, deepIncludes } from './utils' | ||
|
||
// Types | ||
export * from './types' | ||
export type { Query } from './query' | ||
export type { QueryCache } from './queryCache' | ||
export type { ConsoleObject } from './utils' |
Oops, something went wrong.