Skip to content
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

Type-checking errors on fallthrough attributes and AllowedComponentProps #3201

Closed
cexbrayat opened this issue May 19, 2023 · 5 comments · Fixed by #3487
Closed

Type-checking errors on fallthrough attributes and AllowedComponentProps #3201

cexbrayat opened this issue May 19, 2023 · 5 comments · Fixed by #3487
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first

Comments

@cexbrayat
Copy link
Member

Consider a simple component using a Field from the vee-validate library:

<script setup lang="ts">
import { Field } from 'vee-validate';
</script>

<template>
  <Field id="name" name="name" value="Cedric" />
</template>

Note that Field has an id, which is not a prop but a fallthrough attribute, so the resulting HTML is:

<input id="name" name="name">

The problem is vue-tsc (v1.6.5) does not compile, as id is not recognized:

npm run type-check
src/App.vue:6:10 - error TS2345: Argument of type '{ id: string; name: string; value: string; }' is not assignable to parameter of type '{ label?: string | undefined; as?: string | Record<string, any> | undefined; bails?: boolean | undefined; uncheckedValue?: any; validateOnInput?: boolean | undefined; validateOnChange?: boolean | undefined; ... 21 more ...; onVnodeUnmounted?: ((vnode: VNode<...>) => void) | ... 1 more ... | undefined; }'.
  Object literal may only specify known properties, and 'id' does not exist in type '{ label?: string | undefined; as?: string | Record<string, any> | undefined; bails?: boolean | undefined; uncheckedValue?: any; validateOnInput?: boolean | undefined; validateOnChange?: boolean | undefined; ... 21 more ...; onVnodeUnmounted?: ((vnode: VNode<...>) => void) | ... 1 more ... | undefined; }'.

6   <Field id="name" name="name" value="Cedric" />

This only happens with strictTemplates: true in vueCompilerOptions.

I used to get around this by using AllowedComponentProps:

declare module '@vue/runtime-core' {
  interface AllowedComponentProps {
    id?: string;
  }
}

but this does not do the trick here, as now Field is not found at all:

src/App.vue:6:4 - error TS2339: Property 'Field' does not exist on type '{}'.

You can find a small repro here: https://stackblitz.com/edit/github-ekza7z?file=src/App.vue

npm i && npm run type-check

So my questions are:

  • is AllowedComponentProps the correct way to handle the case of attributes here?
  • if so, as it does break the compilation by not finding Field anymore, is there an issue with vue-tsc?
  • or is it something that the vee-validate author could do something about so it would work out of the box?
@so1ve so1ve added bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first and removed bug Something isn't working good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first labels Jun 26, 2023
@so1ve
Copy link
Member

so1ve commented Jun 26, 2023

Not sure i this is the intended behavior :(

@jpoep
Copy link

jpoep commented Aug 4, 2023

I've had this exact issue - it was complaining about fallthrough props only on generic components; Field seems to be one too.

Updating vue-tsc to its current version seems to fix it. Your Stackblitz repro no longer fails its type-check after using vue-tsc 1.8.8.

@cexbrayat
Copy link
Member Author

@jpoep Thanks for checking this. It still fails with v1.8.8 if the project has global components declared

I updated the Stackblitz https://stackblitz.com/edit/github-ekza7z?file=env.d.ts,package.json

/// <reference types="vite/client" />
import type App from './src/App.vue';

declare module '@vue/runtime-core' {
  interface GlobalComponents {
    App: typeof App;
  }
  interface AllowedComponentProps {
    id?: string;
  }
}

@so1ve
Copy link
Member

so1ve commented Aug 17, 2023

This issue will be fixed by #3487, which makes strictTemplates: false work with generic components. If you enable that option, #3443 will occur - but they are different issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants