Skip to content

Commit

Permalink
test(reactivity): support distribution of union types
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoErii committed Dec 24, 2023
1 parent a8d0b1b commit 18b3c56
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,15 @@ type BaseTypes = string | number | boolean
*/
export interface RefUnwrapBailTypes {}

type DistrubuteRef<T> = T extends Ref<infer V>
? unknown extends V
? never
: V
: T
export type ShallowUnwrapRef<T> = {
[K in keyof T]: T[K] extends Ref<infer V>
? V // if `V` is `unknown` that means it does not extend `Ref` and is undefined
: T[K] extends Ref<infer V> | undefined
? unknown extends V
? undefined
: V | undefined
: T[K]
: DistrubuteRef<T[K]>
}

export type UnwrapRef<T> = T extends ShallowRef<infer V>
Expand Down

0 comments on commit 18b3c56

Please sign in to comment.