Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vue-query): use distributive omit to preserve union (#4562)
- Loading branch information
Showing
8 changed files
with
259 additions
and
6 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
82 changes: 82 additions & 0 deletions
82
packages/vue-query/src/__tests__/useInfiniteQuery.types.test.tsx
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,82 @@ | ||
import { InfiniteData } from '@tanstack/query-core' | ||
import { reactive } from 'vue' | ||
import { useInfiniteQuery } from '../useInfiniteQuery' | ||
import { doNotExecute, Equal, Expect, simpleFetcher } from './test-utils' | ||
|
||
describe('Discriminated union return type', () => { | ||
it('data should be possibly undefined by default', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useInfiniteQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
const result: Expect< | ||
Equal<InfiniteData<string> | undefined, typeof query.data> | ||
> = true | ||
return result | ||
}) | ||
}) | ||
|
||
it('data should be defined when query is success', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useInfiniteQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
if (query.isSuccess) { | ||
const result: Expect<Equal<InfiniteData<string>, typeof query.data>> = | ||
true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('error should be null when query is success', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useInfiniteQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
if (query.isSuccess) { | ||
const result: Expect<Equal<null, typeof query.error>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('data should be undefined when query is loading', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useInfiniteQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
if (query.isLoading) { | ||
const result: Expect<Equal<undefined, typeof query.data>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('error should be defined when query is error', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useInfiniteQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
if (query.isError) { | ||
const result: Expect<Equal<unknown, typeof query.error>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
}) |
69 changes: 69 additions & 0 deletions
69
packages/vue-query/src/__tests__/useMutation.types.test.tsx
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,69 @@ | ||
import { reactive } from 'vue' | ||
import { useMutation } from '../useMutation' | ||
import { doNotExecute, Equal, Expect, successMutator } from './test-utils' | ||
|
||
describe('Discriminated union return type', () => { | ||
it('data should be possibly undefined by default', () => { | ||
doNotExecute(() => { | ||
const mutation = reactive( | ||
useMutation({ mutationFn: successMutator<string> }), | ||
) | ||
|
||
const result: Expect<Equal<string | undefined, typeof mutation.data>> = | ||
true | ||
return result | ||
}) | ||
}) | ||
|
||
it('data should be defined when mutation is success', () => { | ||
doNotExecute(() => { | ||
const mutation = reactive( | ||
useMutation({ mutationFn: successMutator<string> }), | ||
) | ||
|
||
if (mutation.isSuccess) { | ||
const result: Expect<Equal<string, typeof mutation.data>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('error should be null when mutation is success', () => { | ||
doNotExecute(() => { | ||
const mutation = reactive( | ||
useMutation({ mutationFn: successMutator<string> }), | ||
) | ||
|
||
if (mutation.isSuccess) { | ||
const result: Expect<Equal<null, typeof mutation.error>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('data should be undefined when mutation is loading', () => { | ||
doNotExecute(() => { | ||
const mutation = reactive( | ||
useMutation({ mutationFn: successMutator<string> }), | ||
) | ||
|
||
if (mutation.isLoading) { | ||
const result: Expect<Equal<undefined, typeof mutation.data>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('error should be defined when mutation is error', () => { | ||
doNotExecute(() => { | ||
const mutation = reactive( | ||
useMutation({ mutationFn: successMutator<string> }), | ||
) | ||
|
||
if (mutation.isError) { | ||
const result: Expect<Equal<unknown, typeof mutation.error>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
}) |
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,78 @@ | ||
import { reactive } from 'vue' | ||
import { useQuery } from '../useQuery' | ||
import { doNotExecute, Equal, Expect, simpleFetcher } from './test-utils' | ||
|
||
describe('Discriminated union return type', () => { | ||
it('data should be possibly undefined by default', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
const result: Expect<Equal<string | undefined, typeof query.data>> = true | ||
return result | ||
}) | ||
}) | ||
|
||
it('data should be defined when query is success', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
if (query.isSuccess) { | ||
const result: Expect<Equal<string, typeof query.data>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('error should be null when query is success', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
if (query.isSuccess) { | ||
const result: Expect<Equal<null, typeof query.error>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('data should be undefined when query is loading', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
if (query.isLoading) { | ||
const result: Expect<Equal<undefined, typeof query.data>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
|
||
it('error should be defined when query is error', () => { | ||
doNotExecute(() => { | ||
const query = reactive( | ||
useQuery({ | ||
queryFn: simpleFetcher, | ||
}), | ||
) | ||
|
||
if (query.isError) { | ||
const result: Expect<Equal<unknown, typeof query.error>> = true | ||
return result | ||
} | ||
}) | ||
}) | ||
}) |
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
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