fix(types): keep readonly infomation during unwrap refs

This commit is contained in:
KazariEX 2025-02-24 14:34:22 +08:00
parent 2dd2feab9c
commit c2f762249c
1 changed files with 7 additions and 1 deletions

View File

@ -486,9 +486,15 @@ function propertyToRef(
export interface RefUnwrapBailTypes {}
export type ShallowUnwrapRef<T> = {
[K in keyof T]: DistributeRef<T[K]>
readonly [K in keyof Pick<T, ReadonlyKeys<T>>]: DistributeRef<T[K]>
} & {
[K in keyof Omit<T, ReadonlyKeys<T>>]: DistributeRef<T[K]>
}
type ReadonlyKeys<O> = {
[K in keyof O]: O[K] extends Readonly<any> ? K : never
}[keyof O]
type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T
export type UnwrapRef<T> =