How should strictTempaltes compiler option be used? #13570
Unanswered
nayakunin
asked this question in
Help/Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I've just recently starting working with Vue coming from the React world. I've gotten used to full type safety, that can be achieved there and I've been quite surprised when I saw that the
strictTemplates
tsconfig compiler options is not enabled by default. Using thestrict: true
option in React never caused any issues for me. I've tried enabling it on a real project, and I immediately saw a bunch of errors. Here is an example of such error:The
id
used in this component is not defined in the props and relies on the fallthrough attributes feature. The issue is that Vue doesn't automatically infer the type of the fallthrough attributes, though there is a compiler option that enables that. I've tried using it, but quickly found out that it only actually infers the types of the variable attributes, like anid
, but it doesn't infer the types of callbacks. An example with enabledfallthroughAttributes
:I've looked for a solution, how the fallthrough attributes can be properly typed an encountered these discussions:
There is a solution in the first discussion that would solve my problem https://github.com/orgs/vuejs/discussions/10262#discussioncomment-8354644, but it seems quite cumbersome and it seems like I'm fighting the compiler. Here is the code for that:
So the question is, is it ever a good idea to enable the
strictTemplates
feature? If you are relying on a component library that doesn't properly type its fallthrough attributes, you seemingly would never be able to use that. I've looked around how other component libraries deal with this issue and found out that some of them don't add types for the attributes, while some others, like prime-vue, have a separate.d.ts
file with theextends ButtonHTMLAttributes
declaration, where they are not required to use the@vue-ignore
statement. Is the approach theprime-vue
uses the only viable approach to be taken? A small example:Are there any real world projects that actually use this feature successfully, and if they do, then how do they deal with the un-typed attributes issue?
Just for a reference, this is an example, of what I'm trying to achieve in React code:
Beta Was this translation helpful? Give feedback.
All reactions