-
-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vue 2 cannot assert type in template #1354
Comments
It seems that your error prompt is not caused by volar, your ide type interface works correctly. I think the reason why your last code can work is that TS has a feature that context judgment can narrow the range of types. Maybe you can try,it works well with me
|
Technically that would work but |
Hi @jaredmcateer, please try <script lang="ts">
import { defineComponent, PropType } from "@vue/composition-api";
export default defineComponent({
props: {
- features: { type: Object as PropType<Record<string, string | boolean>>, required: true }
+ features: { type: Object as PropType<Record<string, 'true' | 'false' | boolean>>, required: true }
},
data() {
return {
feature: 'foo',
};
},
});
</script> |
Minimal test case
https://github.com/jaredmcateer/vue2-volar-type-error
Issue explanation
When passing an object with a variable key to
:checked
on an input element I am getting a type error where the types might not align.I've tried various ways of calming the error but have not found an ideal solution.
I tried changing the line to
:checked="(feature[feature] as boolean)"
which calms the error in the IDE but is a runtime error (unexpected token)Other things I've tried is adding:
v-if="typeof features[feature] === 'boolean'"
and
adding a method that has a type predicate
with
v-if="isBoolean(features[feature])
But these do not work. However if I try them with accessing the property directly such as:
Then it works (but doesn't for my real world usage)
The text was updated successfully, but these errors were encountered: