vue 2.7 template type check for inline function
See original GitHub issueI’m using vue 2.7 with TypeScript
<template>
<div>
<div v-for="(item, index) in arr" :key="index">
<el-input type="text" :value="item" @input="(val) => doSomething(index, val)" />
</div>
</div>
</template>
As code shown above, the problem is @input="(val) => doSomething(index, val)"
part.
- ts error
Parameter 'val' implicitly has an 'any' type.
sincenoImplicitAny
intsconfig
was enabled - Vue 2.7 doesn’t support ts syntax in template as the CHANGELOG said
❌ TypeScript syntax in template expressions (incompatible w/ Vue 2 parser)
ts-ignore
will causingprettier
add leading semi colon which is not valid attribute value@input=" //@ts-ignore ;(val) => doSomething(index, val) "
- Since
val
is an argument so asAny magic won’t work
Any workaround I can do?
Issue Analytics
- State:
- Created a year ago
- Comments:25 (1 by maintainers)
Top Results From Across the Web
vue-template-compiler - npm
This package can be used to pre-compile Vue 2.0 templates into render functions to avoid runtime-compilation overhead and CSP restrictions.
Read more >Template Refs - Vue.js
When the element is unmounted, the argument will be null . You can, of course, use a method instead of an inline function....
Read more >Using Vue with TypeScript - Vue.js
To use TypeScript in SFCs, add the lang="ts" attribute to <script> tags. When lang="ts" is present, all template expressions also enjoy stricter type...
Read more >Class and Style Bindings - Vue.js
A common need for data binding is manipulating an element's class list and its inline styles. Since they are both attributes, we can...
Read more >vue/no-unsupported-features
disallow unsupported Vue.js syntax on the specified version. ... Vue.js 2.7.0+. "style-css-vars-injection" ... SFC CSS variable injection ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I see. Instead of
@ts-ignore
you can use something similar to theasAny
trick:, where
const anyFn = (fn: (val: any) => any) => fn
. And you can annotate it more accurately if you want.Thanks