-
Notifications
You must be signed in to change notification settings - Fork 216
fix: using get with items with onChange is now correctly typed
#577
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
base: main
Are you sure you want to change the base?
Changes from all commits
5511ee9
386a69e
004527b
058453c
43039df
96e1c1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "leva": patch | ||
| --- | ||
|
|
||
| fix: using get with items with onChange is now correctly typed |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,7 +241,11 @@ type Join<Leaf1, Leaf1Key extends keyof Leaf1, Leaf2> = EndLeaf extends Leaf2 | |
|
|
||
| type Tree<IncludeTransient extends boolean, Leaf, LeafKey extends string | number | symbol = ''> = { | ||
| // if it's a folder we run the type check on it's schema key | ||
| 0: Leaf extends { schema: infer Schema } ? { [Key in keyof Schema]: Join<Schema, Key, Schema[Key]> } : never | ||
| // recursively process each item in the folder with Tree to propagate IncludeTransient flag, | ||
| // which ensures items with onChange inside folders are correctly handled for the get function | ||
| 0: Leaf extends { schema: infer Schema } | ||
| ? { [Key in keyof Schema]: Join<Schema, Key, Tree<IncludeTransient, Schema[Key], Key>> }[keyof Schema] | ||
| : never | ||
|
Comment on lines
+244
to
+248
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Folder recursion still hides transient keys from Even with this recursion, 🤖 Prompt for AI Agents |
||
| 1: never | ||
| // if the leaf is an object, we run the type check on each of its keys | ||
| 2: { | ||
|
|
||
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.
🧩 Analysis chain
Type assertions currently fail – fix the folder typing first.
The new
expectTypeblocks don’t compile right now becauseuseControls(...)[2]still reports only'a1' | 'b1'paths;'a2'/'b2'are dropped by the existing types. Until the underlyingTree/folder typing is fixed, these tests will keep failing (yarn test:typeshits the sameFunctionReturnTypeerror shown in CI). Please address the root cause in the type definitions and re-run the type tests.After updating the types, re-check with:
🏁 Script executed:
#!/bin/bash yarn test:typesLength of output: 747
Length of output: 861
🏁 Script executed:
Length of output: 6861
🏁 Script executed:
Length of output: 27
🏁 Script executed:
Length of output: 27
🏁 Script executed:
Length of output: 10685
🏁 Script executed:
Length of output: 3049
🏁 Script executed:
Length of output: 403
🏁 Script executed:
Length of output: 1878
🏁 Script executed:
Length of output: 168
🏁 Script executed:
Length of output: 8864
🏁 Script executed:
Length of output: 2244
🏁 Script executed:
Length of output: 14199
Type assertions fail due to folder() filtering transient items too early.
The getter function type correctly expects transient items (line 16 of useControls.ts uses
SchemaToValues<S, true>), butfolder()(folder.ts) returnsFolderInput<SchemaToValues<S>>, which prematurely filters out transient items. WhenTreelater tries to process the folder schema withIncludeTransient=true, those items are already gone from the type.Fix: Change folder.ts line 4 from
FolderInput<SchemaToValues<S>>toFolderInput<S>so the raw schema reachesTree, which can then apply theIncludeTransientflag correctly.🧰 Tools
🪛 Biome (2.1.2)
[error] 158-158: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.
For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level
(lint/correctness/useHookAtTopLevel)
[error] 174-174: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.
For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level
(lint/correctness/useHookAtTopLevel)
🪛 GitHub Check: Build, lint, and test
[failure] 174-174:
Argument of type 'FunctionReturnType<{ a: FolderInput<{ b1: number; a1: number; }>; }>' is not assignable to parameter of type '[{ a1: number; }, (value: { a1?: number | undefined; b1?: number | undefined; b2?: string | undefined; }) => void, <T extends "a1" | "b1" | "b2">(path: T) => { a1: number; b1: number; b2: string; }[T]]'.
[failure] 158-158:
Argument of type 'FunctionReturnType<{ a: FolderInput<{ a1: number; }>; }>' is not assignable to parameter of type '[{ a1: number; }, (value: { a1?: number | undefined; a2?: string | undefined; }) => void, <T extends "a1" | "a2">(path: T) => { a1: number; a2: string; }[T]]'.
🤖 Prompt for AI Agents