mirror of https://github.com/vuejs/core.git
parent
09bb3e996e
commit
e816812f10
|
@ -280,13 +280,10 @@ export interface RefUnwrapBailTypes {}
|
||||||
|
|
||||||
export type ShallowUnwrapRef<T> = {
|
export type ShallowUnwrapRef<T> = {
|
||||||
[K in keyof T]: T[K] extends Ref<infer V>
|
[K in keyof T]: T[K] extends Ref<infer V>
|
||||||
? V
|
? V // if `V` is `unknown` that means it does not extend `Ref` and is undefined
|
||||||
: // if `V` is `unknown` that means it does not extend `Ref` and is undefined
|
: T[K] extends Ref<infer V> | undefined
|
||||||
T[K] extends Ref<infer V> | undefined
|
? unknown extends V ? undefined : V | undefined
|
||||||
? unknown extends V
|
: T[K]
|
||||||
? undefined
|
|
||||||
: V | undefined
|
|
||||||
: T[K]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UnwrapRef<T> = T extends ShallowRef<infer V>
|
export type UnwrapRef<T> = T extends ShallowRef<infer V>
|
||||||
|
@ -303,7 +300,7 @@ export type UnwrapRefSimple<T> = T extends
|
||||||
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
|
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
|
||||||
| { [RawSymbol]?: true }
|
| { [RawSymbol]?: true }
|
||||||
? T
|
? T
|
||||||
: T extends Array<any>
|
: T extends ReadonlyArray<any>
|
||||||
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
|
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
|
||||||
: T extends object & { [ShallowReactiveMarker]?: never }
|
: T extends object & { [ShallowReactiveMarker]?: never }
|
||||||
? {
|
? {
|
||||||
|
|
|
@ -60,3 +60,14 @@ describe('shallowReadonly ref unwrap', () => {
|
||||||
expectType<Ref>(r.count.n)
|
expectType<Ref>(r.count.n)
|
||||||
r.count.n.value = 123
|
r.count.n.value = 123
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #3819
|
||||||
|
describe('should unwrap tuple correctly', () => {
|
||||||
|
const readonlyTuple = [ref(0)] as const
|
||||||
|
const reactiveReadonlyTuple = reactive(readonlyTuple)
|
||||||
|
expectType<Ref<number>>(reactiveReadonlyTuple[0])
|
||||||
|
|
||||||
|
const tuple: [Ref<number>] = [ref(0)]
|
||||||
|
const reactiveTuple = reactive(tuple)
|
||||||
|
expectType<Ref<number>>(reactiveTuple[0])
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue