【发布时间】:2021-08-11 09:52:27
【问题描述】:
复制:https://github.com/wenfangdu/d-ts-conflict-repro
shims-vue.d.ts
/* eslint-disable */
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
/* eslint-enable */
import 'vue'
declare module 'vue' {
interface HTMLAttributes extends interface {
vModel?: unknown
}
}
运行npm run serve,开发服务器启动后,打印出这些错误:
ERROR in src/main.ts:2:17
TS7016: Could not find a declaration file for module './App.vue'. 'D:/Repos/d-ts-conflict-repro/src/App.vue.js' implicitly has an 'any' type.
1 | import { createApp } from 'vue'
> 2 | import App from './App.vue'
| ^^^^^^^^^^^
3 | import router from './router'
4 | import store from './store'
5 |
ERROR in src/router/index.ts:17:46
TS7016: Could not find a declaration file for module '../views/About.vue'. 'D:/Repos/d-ts-conflict-repro/src/views/About.vue.js' implicitly has an 'any' type.
15 | // which is lazy-loaded when the route is visited.
16 | component: () =>
> 17 | import(/* webpackChunkName: "about" */ '../views/About.vue'),
| ^^^^^^^^^^^^^^^^^^^^
18 | },
19 | ]
20 |
我做错了什么?
【问题讨论】:
-
你为什么要添加第二个声明?
-
@BoussadjraBrahim 我想在
<input />上使用vModel。 -
vue 指令可以作为 html 属性正常工作
-
@BoussadjraBrahim 我正在使用 TSX,
v-model是允许的,但vModel是不允许的,所以我不得不添加这个。如果我把它放在另一个.d.ts中,一切正常,但是当它们在同一个.d.ts中时它会抛出,我不明白为什么。 -
但是为什么要使用
vModel而不是v-model?
标签: typescript vue.js typescript-typings vuejs3 vue-cli