vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.87k stars 400 forks source link

fix: should try casting dynamic slot name into constant #4669

Closed KermanX closed 3 months ago

KermanX commented 3 months ago

fix #4668.

Introduced a new helper:

function __VLS_tryAsConstant<const T>(t: T): T;

which is used to infer the type of an arbitrary expression like as const, but not throwing errors when this can't be done. For example, ("1" + "2") as const will be an error, but __VLS_tryAsConstant("1" + "2") will just be of type string.

btw, I think __VLS_tryAsConstant can be used in other places to provide more precise type info - but it may cause performance issues.

davidmatter commented 3 months ago

You were faster, nice work

johnsoncodehk commented 3 months ago

Thanks!