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

strictTemplates errors on class, id, @click #3443

Closed
Doeke opened this issue Jul 24, 2023 · 8 comments
Closed

strictTemplates errors on class, id, @click #3443

Doeke opened this issue Jul 24, 2023 · 8 comments

Comments

@Doeke
Copy link

Doeke commented Jul 24, 2023

In some situations type checking fails on basic attributes and events when strictTemplates: true

In this repro link I demonstrate 3 different issues (run npx vue-tsc):

https://stackblitz.com/edit/vitejs-vite-avohbf?file=src%2FApp.vue

  • Adding id=".." to component tag sometimes causes Object literal may only specify known properties, and 'id' does not exist in type ...
  • Adding class=".." is not allowed in some cases for example with Transition/TransitionGroup and causes Object literal may only specify known properties, but 'class' does not exist in type 'TransitionProps'
  • Adding @click="onClick" is not allowed on component tags (but only if there are no props defined?) and causes Type '{ onClick: any; }' has no properties in common with type

The first two (id and class) can be worked around by adding dataAttributes: ["id", "class"] to tsconfig. For @click errors a workaround seems to be to define one or more props on the tag.

@davidmatter
Copy link
Collaborator

davidmatter commented Aug 5, 2024

This one seems to be resolved in 2.x. Feel free to create a new issue if you're still having issues, thanks!

@cooper667
Copy link

cooper667 commented Aug 6, 2024

I'm still seeing the 3rd case:

Adding @click="onClick" is not allowed on component tags (but only if there are no props defined?) and causes Type '{ onClick: any; }' has no properties in common with type

Adding a redundant prop still works as a workaround.

├─┬ [email protected]
│ ├─┬ @vue/[email protected]
│ │ └── [email protected]

@davidmatter
Copy link
Collaborator

Can you be more specific about the 3rd point? Can you reproduce on https://play.vuejs.org/?

@cooper667
Copy link

image

Line 19 is an error, 20 and 21 are not.

src/App.vue(19,4): error TS2559: Type '{ onClick: any; }' has no properties in common with type '{ readonly msg?: string | undefined; key?: string | number | symbol | undefined; ref?: VNodeRef | undefined; ref_for?: boolean | undefined; ref_key?: string | undefined; ... 7 more ...; style?: unknown; }'.

https://stackblitz.com/edit/vitejs-vite-bukhvb?file=src%2FApp.vue

@KazariEX
Copy link
Collaborator

KazariEX commented Aug 7, 2024

It works on my machine with latest version of vue. Maybe you just need to update deps?

@davidmatter
Copy link
Collaborator

Same, @Doeke please share more information about your setup (open a new issue to get inspired by a good issue template).

@davidmatter davidmatter removed the good reproduction ✨ This issue provides a good reproduction, we will be able to investigate it first label Aug 7, 2024
@cooper667
Copy link

Yea, bumping vue fixes that stackblitz

Still have the local issue, but i'll make a new issue when I can replicate in a useful way

@Doeke
Copy link
Author

Doeke commented Aug 16, 2024

@davidmatter

Same, @Doeke please share more information about your setup (open a new issue to get inspired by a good issue template).

Done:

#4699

Hope this is enough information, would really like to be able to use the strictTemplates feature for our project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants