mirror of https://github.com/vuejs/core.git
Merge 166a5c1eba
into 56be3dd4db
This commit is contained in:
commit
02290ba666
|
@ -11,6 +11,7 @@ import {
|
||||||
defineComponent,
|
defineComponent,
|
||||||
h,
|
h,
|
||||||
reactive,
|
reactive,
|
||||||
|
readonly,
|
||||||
ref,
|
ref,
|
||||||
withKeys,
|
withKeys,
|
||||||
withModifiers,
|
withModifiers,
|
||||||
|
@ -190,6 +191,7 @@ describe('with object props', () => {
|
||||||
f: reactive({
|
f: reactive({
|
||||||
g: ref('hello' as GT),
|
g: ref('hello' as GT),
|
||||||
}),
|
}),
|
||||||
|
m: readonly(ref(1)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
provide() {
|
provide() {
|
||||||
|
@ -259,6 +261,9 @@ describe('with object props', () => {
|
||||||
// setup context properties should be mutable
|
// setup context properties should be mutable
|
||||||
this.c = 2
|
this.c = 2
|
||||||
|
|
||||||
|
// @ts-expect-error setup context readonly properties should not be mutable
|
||||||
|
this.m = 2
|
||||||
|
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import {
|
import {
|
||||||
type IfAny,
|
type IfAny,
|
||||||
|
type IfEquals,
|
||||||
hasChanged,
|
hasChanged,
|
||||||
isArray,
|
isArray,
|
||||||
isFunction,
|
isFunction,
|
||||||
|
@ -486,9 +487,20 @@ function propertyToRef(
|
||||||
export interface RefUnwrapBailTypes {}
|
export interface RefUnwrapBailTypes {}
|
||||||
|
|
||||||
export type ShallowUnwrapRef<T> = {
|
export type ShallowUnwrapRef<T> = {
|
||||||
[K in keyof T]: DistributeRef<T[K]>
|
[K in keyof Pick<T, MutableKeys<T>>]: DistributeRef<T[K]>
|
||||||
|
} & {
|
||||||
|
readonly [K in keyof Omit<T, MutableKeys<T>>]: DistributeRef<T[K]>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MutableKeys<T> = {
|
||||||
|
[K in keyof T]-?: IfEquals<
|
||||||
|
{ [P in keyof T[K]]: T[K][P] },
|
||||||
|
{ -readonly [P in keyof T[K]]: T[K][P] },
|
||||||
|
K,
|
||||||
|
never
|
||||||
|
>
|
||||||
|
}[keyof T]
|
||||||
|
|
||||||
type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T
|
type DistributeRef<T> = T extends Ref<infer V, unknown> ? V : T
|
||||||
|
|
||||||
export type UnwrapRef<T> =
|
export type UnwrapRef<T> =
|
||||||
|
|
|
@ -13,6 +13,10 @@ export type LooseRequired<T> = { [P in keyof (T & Required<T>)]: T[P] }
|
||||||
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
||||||
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
|
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/52443276/how-to-exclude-getter-only-properties-from-type-in-typescript/52473108#52473108
|
||||||
|
export type IfEquals<A, B, Y, N> =
|
||||||
|
(<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? Y : N
|
||||||
|
|
||||||
export type IsKeyValues<T, K = string> = IfAny<
|
export type IsKeyValues<T, K = string> = IfAny<
|
||||||
T,
|
T,
|
||||||
false,
|
false,
|
||||||
|
|
Loading…
Reference in New Issue