mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
fix(types): cover more SyncPatch cases
This commit is contained in:
parent
d913dfc444
commit
cf44dd02ca
1 changed files with 11 additions and 5 deletions
16
src/index.d.ts
vendored
16
src/index.d.ts
vendored
|
|
@ -241,6 +241,8 @@ declare namespace Charm {
|
|||
readonly __none: "__none";
|
||||
}
|
||||
|
||||
type MaybeNone<T> = undefined extends T ? None : never;
|
||||
|
||||
/**
|
||||
* A partial patch that can be applied to the state to update it. Represents
|
||||
* the difference between the current state and the next state.
|
||||
|
|
@ -248,11 +250,15 @@ declare namespace Charm {
|
|||
* If a value was removed, it is replaced with `None`. This can be checked
|
||||
* using the `sync.isNone` function.
|
||||
*/
|
||||
type SyncPatch<State> = {
|
||||
readonly [P in keyof State]?:
|
||||
| (State[P] extends object ? SyncPatch<State[P]> : State[P])
|
||||
| (undefined extends State[P] ? None : never);
|
||||
};
|
||||
type SyncPatch<State> =
|
||||
| MaybeNone<State>
|
||||
| (State extends ReadonlyMap<infer K, infer V> | Map<infer K, infer V>
|
||||
? ReadonlyMap<K, SyncPatch<V> | None>
|
||||
: State extends readonly (infer T)[]
|
||||
? readonly (SyncPatch<T> | None | undefined)[]
|
||||
: State extends object
|
||||
? { readonly [P in keyof State]?: SyncPatch<State[P]> }
|
||||
: State);
|
||||
|
||||
/**
|
||||
* A payload that can be sent from the server to the client to synchronize
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue