mik*_*eym 7 typescript vue.js vue-cli
我的 Vue 2.2.3 应用程序无法构建,并出现 4 个与 TypeScript 相关的错误,我不确定如何修复。
控制台如下所示:
Failed to compile with 4 errors 6:08:46 PM
error in node_modules/vue/types/jsx.d.ts:39:7
TS1110: Type expected.
37 | * https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
38 | */
> 39 | [v: `--${string}`]: string | number | undefined
| ^^^^^
40 | }
41 |
42 | type Booleanish = boolean | 'true' | 'false'
error in node_modules/vue/types/jsx.d.ts:39:20
TS1005: ';' expected.
37 | * https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
38 | */
> 39 | [v: `--${string}`]: string | number | undefined
| ^
40 | }
41 |
42 | type Booleanish = boolean | 'true' | 'false'
error in node_modules/vue/types/jsx.d.ts:39:21
TS1128: Declaration or statement expected.
37 | * https://github.com/frenic/csstype#what-should-i-do-when-i-get-type-errors
38 | */
> 39 | [v: `--${string}`]: string | number | undefined
| ^
40 | }
41 |
42 | type Booleanish = boolean | 'true' | 'false'
error in node_modules/vue/types/jsx.d.ts:40:1
TS1128: Declaration or statement expected.
38 | */
39 | [v: `--${string}`]: string | number | undefined
> 40 | }
| ^
41 |
42 | type Booleanish = boolean | 'true' | 'false'
43 | type Numberish = number | string
ERROR Error: Build failed with errors.
Run Code Online (Sandbox Code Playgroud)
我点击控制台输出中的链接,得到以下代码。我将该文件添加到我的项目 src 目录中。
// My css.d.ts file
import type * as CSS from 'csstype';
declare module 'csstype' {
interface Properties {
// Add a missing property
WebkitRocketLauncher?: string;
// Add a CSS Custom Property
'--theme-color'?: 'black' | 'white';
// ...or allow any other property
[index: string]: any;
}
}
Run Code Online (Sandbox Code Playgroud)
当然,上面的文件没有解决问题,我也遇到了相同的 TypeScript 错误。我尝试删除 '--theme-color'?: 'black' | 'white';但它也不起作用。
坦率地说,我不确定如何解决这些问题并使构建通过。奇怪的是,该应用程序在我的生产服务器上构建没有任何问题。
我想补充一点,我也在使用 Veutify,它可能会也可能不会导致其中一些错误。
任何帮助深表感谢。
我今天看到同样的错误Vue: 2.6.11。不知道如何处理它。
更新
我通过更新 package.json 中的 TypeScript 解决了这个问题。我认为不支持字符串文字。
我更新到TS版本了4.4.4