Skip to content

withDefaults disables the use of discriminated unions (only in scripts, not in templates) #9335

Closed
@davidmatter

Description

@davidmatter

Vue version

3.3.4

Link to minimal reproduction

https://play.vuejs.org/#eNrtVcFu2kAQ/ZWRLyZSsIXaEwWapsmhVdJGTdQe4hxcPIZN7F1rdw20hH/v7NgGQ2hKpPbWC4SdN2/ezM6+LL13RRHMSvT63sCMtSgsGLRlAVksJ8PIsybyYIIStRjTzxvAhUWZGDBWCzmJvFEkIynyQmkL71VeQKpVDpEXhO6Xo468LUBvG9FrIJEchJUCphxYzIsstki/BkwM/VwlmHVncVYiabn1LRrr35FAF6CTvMysKDKiC5us3ovSwIif7uSC/mSKcK3CO6ZZjJVMxSS4N0rSwJaRBOpjTGVEhvpzYYWSNK8+cMTF4ixT8498ZnWJx835eIrjhz3n92bhziLvSqNBPSNN65iN9QRtFT6//kQX0QpSK6Xr4JngFzQqK53GCnZayoRkt3Cs9gNfFd3tjTl3d22appxQh1wxPvLo3tyEf9f6Ru6r4BXnRXJFU2zW4tCN4xWr92cJbtilxQRW1Rr5xOS/cQtjfxQIp7HBK60KA8NKibvQt33wL3x4BP+SP699UsJrKy3qNB4jcM6l24P1gm+omMjtCvE0u0IU1Vn21e1VH25u7/azXtMoM/wDrWHQU9Kakntr+mqzPraUOyAtqLFQ1Mi5sNMzTGOKmk6CqZBV6QF/jjpHx5sh8Yyo3NGGZkEUzbw7nSMYjiq4SKHDJQKnFYbDYWsuR80GaLpULSstDKyaCu6VkB2qwguxhvnr2s/5wLQ3OlNopG9hrvQDN7jV5SAkCAETMYNZV6TudT/VyCsFUKNSpR0MhGzNvoYALJf5akWxFDXXNA7XaGKWkGjYK+pv97VcLtZZSVsxJddLz35EgpvsttNU697N42LHa6rA9kNj/3QPemptYfphOE4kpVEnYqYDiTaURR6eECzUpbQix26i8hN6lcFrqm5s+zhAk3e/azUn9yGSljm4fLYk3dW0yaiddRxWdietXXon9KT8jnHwf4u/7Rz/vWOPd+yzi39sDbuewFM5xBO+8btkM2jLfokXHOgGa0eoc3bffusVr34BHdY3dA==

Steps to reproduce

Check Comp.vue - in the template, the discriminated union can be inferred correctly. Not so in the script.
This is probably because withDefaults uses Omit to combine the required and optional props and because Omit follows the following behavior: microsoft/TypeScript#31501.

I'm not sure why the discriminated union is inferred correctly in the template, though.
defineProps itself, without defaults, works correctly - check Comp1.vue.

image

What is expected?

Discriminated unions should work in scripts as well as in templates.

What is actually happening?

Only works in templates.

System Info

No response

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    has PRA pull request has already been submitted to solve the issuescope: types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions