vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
46.88k stars 8.22k forks source link

Setup script generic type problem #11394

Open Frantab opened 2 months ago

Frantab commented 2 months ago

Vue version

3.4.32

Link to minimal reproduction

https://play.vuejs.org/#eNqdVE1v2zAM/SusL3aBxsawnTK7RbcGWId+BG3Qy7yDazOpOlk2JDlNkeW/j5Js10mDFuvFsMhH6vGR1No7retw2aA39mKVS1ZrUKib+jgVrKwrqWENEuewgbmsSvAJ6veuc1E3unWEkT2ZXP7XQbC1zp5r7FOEkaajMqhU5JVQGpYZbxASc1Pw6ZAcceTIEA06aCxrnmmkE0B8MBqBSdjRfagaXsAzcg76IdMgmvIeJTAFotKQKcUWIrvnCLoCpSUTC/hLIIKPRi6jq2M5KqsCeZJ6lk7qwdgQpXNfQ3hr48kVUWQcDYh5R55WVM2cLcJHVQkSdG2Sp15elTXjKK9rzaja1BuD9Rhfxnn19NPatGzwqLPnD5j/2WN/VCtjS72pRIVySSx7n87kArVzT26vcEX/vZNKazih33DeoKp4Yzg62LdGFER7gLNsz21nSYWZmqw0CtUVZYga5MbiScUGv79R+gvdz+EXG5eKDanYj9HuSALPxIK6oSkPLFCgZDkdZ0DFoCjUy6gdwR0N0x5HeOVm46QbknYQxnvBrtkE3p6aMQhcGl2GO2Ka3GgsthblP/YgimB6cz29pQihUc6zHGEqq1o5wQySSBKUVOq2prb+BAqcM4EWHdvvcWB2yCa9vD6bXFBWF2EH/K5dNhd2aUzx3SDk7HR22gVgwbTZnS6mKzP+Mbu8sCVNOJYo9C/fLo3/+ziwhKm1wWHXbEntk2Jwe+gW/iBJnKQn4LQOdiGHpLZvFOrGiiYhEPhkIX1+NofAihEanSChtLst77EAVOJAh/b5uMftkejArzgT4/Z6S592xMpYUA3upgE9mhRKZdkTf0Cu8H0aW8P2ERq9Y/v6TsPNe+9rwZb2h37ZzsO4NQ7tK0iwyIW8eg/NeIda0SLjyq4BksaDTbBatCuZgO8a4Ns+t7tHVqeHsVIJ3uYflE9Dxw==

Steps to reproduce

enum Type { Number = 'number', String = 'string', }

  1. make generic type like generic="T extends Type, V = T extends Type.Number ? number | null : T extends Type.String ? string | null : never">
  2. try to use V. It will never be used as resolved by T

What is expected?

V should be generic based on the given T

What is actually happening?

V is never resolved inside vue component nor when using the component

System Info

VS code IDE

Any additional comments?

When defining model as const modelValue = defineModel<T extends Type.Number ? number | null : T extends Type.String ? string | null : never>(); than when using the component, type is calculated from the generic T.

edison1105 commented 2 months ago

/cc @so1ve

so1ve commented 2 months ago

This is expected behavior: https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgEwKYDNgDtUFkJoA2cAvnOlBCHAEQBuArqjQNwBQbqWD1AklmAYwAKgE8wqRGzgy4AOR4AjVFDgBeWtxDKoNADTTZAZRhRsAc3W0AzqYv62JDugZYAxjGAQs5CBAA8wnCoAB4wXMjWcPyCIuKoenAAalZBoeFYkdECQmISAHQK2ipwAPxwWjpwAD4VDITEAFxwaWERUTG58fkmZliW5bZ9lrXcDXDNOHQqAHwAFACUUrJwhKjwYJRg1gCEzUgw8c1BJOwrbt62cCAEqIRJAIaETFZomDj4RP5J8wvshjJgOg4HNNhBtvlDhJ1GoNJ04gUijolggAStrrd7k8mPk6NjJBoAIxnWROJxAA

so1ve commented 2 months ago

V = ... is not associated with T. It can be any other type.

Frantab commented 2 months ago

Ok, I see the problem. I tried to write it differently in TS: Ts playground

Then I tried it in my IDE and it works for the component itself so when I pass InputType.String, will tell me I need to pass string | null in prop modelValue. In the Githubissues.

  • Githubissues is a development platform for aggregating issues.