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,
|
||||
h,
|
||||
reactive,
|
||||
readonly,
|
||||
ref,
|
||||
withKeys,
|
||||
withModifiers,
|
||||
|
@ -190,6 +191,7 @@ describe('with object props', () => {
|
|||
f: reactive({
|
||||
g: ref('hello' as GT),
|
||||
}),
|
||||
m: readonly(ref(1)),
|
||||
}
|
||||
},
|
||||
provide() {
|
||||
|
@ -259,6 +261,9 @@ describe('with object props', () => {
|
|||
// setup context properties should be mutable
|
||||
this.c = 2
|
||||
|
||||
// @ts-expect-error setup context readonly properties should not be mutable
|
||||
this.m = 2
|
||||
|
||||
return null
|
||||
},
|
||||
})
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {
|
||||
type IfAny,
|
||||
type IfEquals,
|
||||
hasChanged,
|
||||
isArray,
|
||||
isFunction,
|
||||
|
@ -486,9 +487,20 @@ function propertyToRef(
|
|||
export interface RefUnwrapBailTypes {}
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
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<
|
||||
T,
|
||||
false,
|
||||
|
|
Loading…
Reference in New Issue