这是使用typescript和volar扩展的vue js 2(使用2.7)特有的
当使用<script lang="ts">
时,<template>
内容也会得到typescript通知,即使内容不支持typescript
。
<my-component @change="(selection)=>doStuff(selection, index)"></my-component>
将显示错误(在IDE中,但编译和工作)
参数'selection'隐式具有'any'类型。ts(7006)
添加类型会使代码无效,因为该类型未被解析
<my-component @change="(selection:string)=>doStuff(selection, index)"></my-component>
意外标记,预期","(1:429)
希望这能帮助到面临同样问题的人
2.7发布的博客文章中有关于volar兼容性的说明:
足底的兼容性2.7改进了类型定义,因此不再需要为Volar模板类型推断而安装@vue/runtime-dom支持。现在你只需要在tsconfig.json中做如下配置:
{ // ... "vueCompilerOptions": { "target": 2.7 } }
然而,为了抑制模板中的typescript检查,也需要使用experimentalDisableTemplateSupport
选项
tsconfig.json
:
"vueCompilerOptions": {
"target": 2.7,
"experimentalDisableTemplateSupport": true
},