Skip to content

Union types are not unwrapped properly #9903

Closed
@jods4

Description

@jods4

Vue version

3.313

Link to minimal reproduction

https://play.vuejs.org/#eNp9UctOwzAQ/JWVL7RSSUEVl5CmgqoHkFpQgZsvUbp5FMe27E0fivLv2KkaioR6seyd2fHMbsOetA52NbKQRTY1pSawSLUGkch8yhlZzmIuy0orQ9DAl9ybRK8xG4Hxh7tBC5lRFdw4mRsuuUyVtASVzWEKy4SKwCRyo6rBEGK4u32AmW8dNCCTCkPg7Kg4g3YIIchaiEcvQUeNsOwU+h8jX1SZF44dKRqf/Dp37kFYaZEQuhdAVNzHTeOJs8B/EgiUORXQttHYQb73gs9GLqXznJV5sLVKulE0XoWzVFW6FGjeNJUuE2chdIjHEiHU/rWrkalxdK6nBabf/9S39uBrnL0btGh2yFmPUWJypBO8+Fjhwd17sFKbWjj2FXCNVonaezzRnmu5cbYveJ3bl26Jpcw/7eJAKO051B+jlkyZ0sptYu6j9ASPtx2LM7fp+ZXZ/OaZBJOuj8uWtT+kU81Z

Steps to reproduce

Create a type that is the union of a Ref of a non-primitive type and null, e.g. type X = Ref<{ name: string }> | null.

What is expected?

UnwrapRef<X> should be { name: string } | null.

What is actually happening?

Well... in TS script block it looks like UnwrapRef<X> is right, but when looked at inside the template block, it's still Ref<{ name: string }> | null. (see repro link)

As a consequence, using x in template (where refs are unwrapped automatically) fails type-checking as TS doesn't see the right type.
image

System Info

See repro in Vue SFC Playground.

Any additional comments?

This is the same issue as #3990 which was fixed. Maybe it regressed in a later release?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions