Skip to content

Commit

Permalink
fix(types): infer the first generic type of Ref correctly (#12094)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX authored Oct 3, 2024
1 parent 57315ab commit c97bb84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/reactivity/src/reactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export type DeepReadonly<T> = T extends Builtin
? WeakSet<DeepReadonly<U>>
: T extends Promise<infer U>
? Promise<DeepReadonly<U>>
: T extends Ref<infer U>
: T extends Ref<infer U, unknown>
? Readonly<Ref<DeepReadonly<U>>>
: T extends {}
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
Expand Down
6 changes: 3 additions & 3 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,12 @@ export type ShallowUnwrapRef<T> = {
[K in keyof T]: DistributeRef<T[K]>
}

type DistributeRef<T> = T extends Ref<infer V> ? V : T
type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T

export type UnwrapRef<T> =
T extends ShallowRef<infer V, infer _>
T extends ShallowRef<infer V, unknown>
? V
: T extends Ref<infer V, infer _>
: T extends Ref<infer V, unknown>
? UnwrapRefSimple<V>
: UnwrapRefSimple<T>

Expand Down

0 comments on commit c97bb84

Please sign in to comment.