-
Notifications
You must be signed in to change notification settings - Fork 152
Fix ordering of ts update overloads & fix a lot of type errors in tests #166
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b1fd177
Fix ordering of ts update overloads
KyleAMathews 09fbe80
Fix types in tests
KyleAMathews dd02d11
add changeset
KyleAMathews 5fe6024
fix build
KyleAMathews 06dd623
Fix type oddness where build/tests fighting
KyleAMathews 5b2ee92
prettier
KyleAMathews 7cedaa8
Fixes
KyleAMathews 16cea04
MOER
KyleAMathews fb889b1
Merge remote-tracking branch 'origin/main' into fix-update-types
KyleAMathews 6c89fd6
Fix example
KyleAMathews File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@tanstack/db": patch | ||
| --- | ||
|
|
||
| Fix ordering of ts update overloads & fix a lot of type errors in tests |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
| import { assertType, describe, expectTypeOf, it } from "vitest" | ||
| import type { CollectionImpl } from "../src/collection" | ||
| import type { OperationConfig } from "../src/types" | ||
|
|
||
| describe(`Collection.update type tests`, () => { | ||
| type TypeTestItem = { id: string; value: number; optional?: boolean } | ||
|
|
||
| const updateMethod: CollectionImpl<TypeTestItem>[`update`] = (() => {}) as any // Dummy assignment for type checking | ||
|
|
||
| it(`should correctly type drafts for multi-item update with callback (Overload 1)`, () => { | ||
| updateMethod([`id1`, `id2`], (drafts) => { | ||
| expectTypeOf(drafts).toEqualTypeOf<Array<TypeTestItem>>() | ||
| // @ts-expect-error - This line should error because drafts is an array, not a single item. | ||
| assertType<TypeTestItem>(drafts) | ||
| }) | ||
| }) | ||
|
|
||
| it(`should correctly type drafts for multi-item update with config and callback (Overload 2)`, () => { | ||
| const config: OperationConfig = { metadata: { test: true } } | ||
| updateMethod([`id1`, `id2`], config, (drafts) => { | ||
| expectTypeOf(drafts).toEqualTypeOf<Array<TypeTestItem>>() | ||
| // @ts-expect-error - This line should error. | ||
| assertType<TypeTestItem>(drafts) | ||
| }) | ||
| }) | ||
|
|
||
| it(`should correctly type draft for single-item update with callback (Overload 3)`, () => { | ||
| updateMethod(`id1`, (draft) => { | ||
| expectTypeOf(draft).toEqualTypeOf<TypeTestItem>() | ||
| // @ts-expect-error - This line should error because draft is a single item, not an array. | ||
| assertType<Array<TypeTestItem>>(draft) | ||
| }) | ||
| }) | ||
|
|
||
| it(`should correctly type draft for single-item update with config and callback (Overload 4)`, () => { | ||
| const config: OperationConfig = { metadata: { test: true } } | ||
| updateMethod(`id1`, config, (draft) => { | ||
| expectTypeOf(draft).toEqualTypeOf<TypeTestItem>() | ||
| // @ts-expect-error - This line should error. | ||
| assertType<Array<TypeTestItem>>(draft) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So happy to se you add this rule 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha I'll do the merge this time then 👍