Subscribe on changes!

ref should not unwrap all properties of the entity type

avatar
Feb 20th 2022

Version

3.2.31

Reproduction link

www.typescriptlang.org/play

Steps to reproduce

Reproduction link

What is expected?

ref should not unwrap all properties of the entity type

What is actually happening?

Reproduction link

avatar
Feb 20th 2022

You can use the RefUnwrapBailTypes: https://github.com/vuejs/core/blob/main/packages/reactivity/src/ref.ts#L252-L269 to avoid unwrapping.

avatar
Feb 20th 2022

It can solve the tuple type recursion problem, but it is buggy in the source code. Hope you look at this line of code (https://github.com/vuejs/core/blob/main/packages/reactivity/src/ref.ts#L297), the extends ? : evaluation is problematic, for all object type is always true.

interface X {
    a: 1
    b: 2
    c: 3
    d: 4
}

// bug line: https://github.com/vuejs/core/blob/main/packages/reactivity/src/ref.ts#L297

type Unwrap<T> = T extends (object & { xx?: never }) ? true : false
{
    type Test1 = Unwrap<X> // true
    //   ^?
    type Test2 = Unwrap<X & { xx: never }> // true
    //   ^?
}

ts playground

And a project defines many object types, developers do not need to put all object types into RefUnwrapBailTypes