Skip to content

Commit 9805e29

Browse files
committed
feat: added more flexibility on signal update
1 parent a4bf5b4 commit 9805e29

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/lib/state/Signal.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ import { SIGNAL_RESET } from "./constants"
33

44
/**
55
* Distributive helper to validate the shape of the updater function
6-
* and prevent covariance
6+
* and prevent covariance. Distributes over both T and U so union state
7+
* types work (updater can return any member of the union).
78
*/
8-
// biome-ignore lint/suspicious/noExplicitAny: Expected to prevent covariance
9-
type ValidateShape<T, U> = T extends any
10-
? U extends T
11-
? U extends object
12-
? { [K in keyof U]: K extends keyof T ? T[K] : never }
13-
: U
9+
// biome-ignore lint/suspicious/noExplicitAny: distributive conditional over U and T for union support
10+
type ValidateShape<T, U> = U extends any
11+
? // biome-ignore lint/suspicious/noExplicitAny: distributive over T
12+
T extends any
13+
? U extends T
14+
? U extends object
15+
? { [K in keyof U]: K extends keyof T ? T[K] : never }
16+
: U
17+
: never
1418
: never
1519
: never
1620

0 commit comments

Comments
 (0)