我正在尝试将Vuejs应用程序转换为增量使用Typescript并面临一些构建问题。应用程序的package.json显示"@vue/cli-plugin-typescript": "^4.3.1", "typescript": "^3.5.2",
我能够通过以下方式解决一些构建问题一个。创建.d.ts
文件,例如:通过使用import VueTour from 'vue-tour';
main.ts
文件,修复了vue-tour.d.ts
中与declare module 'vue-tour';
相关的构建错误b。在构建行错误之前添加// @ts-ignore
。例如:
// @ts-ignore
import axios from "./axios.js";
~~ src \ axios.js
import axios from 'axios'
const domain = ""
export default axios.create({domain})
不是使用// @ts-ignore
,而是如何创建.d.ts
文件来解决构建问题?
我也有与AWS Amplify生成的类型和我们使用的自定义路由器实例相关的构建错误。
解决这些构建问题的推荐方法是什么?
~~ src \ router.js
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
const router = new Router({............
});
export default router;
内部版本1:
126:10 No overload matches this call.
Overload 1 of 3, '(options?: ThisTypedComponentOptionsWithArrayProps<Vue, object, object, object, never> | undefined): CombinedVueInstance<Vue, object, object, object, Record<...>>', gave the following error.
Argument of type '{ router: any; store: any; i18n: any; acl: any; render: (h: CreateElement) => VNode; }' is not assignable to parameter of type 'ThisTypedComponentOptionsWithArrayProps<Vue, object, object, object, never>'.
Object literal may only specify known properties, and 'router' does not exist in type 'ThisTypedComponentOptionsWithArrayProps<Vue, object, object, object, never>'.
Overload 2 of 3, '(options?: ThisTypedComponentOptionsWithRecordProps<Vue, object, object, object, object> | undefined): CombinedVueInstance<Vue, object, object, object, Record<...>>', gave the following error.
Argument of type '{ router: any; store: any; i18n: any; acl: any; render: (h: CreateElement) => VNode; }' is not assignable to parameter of type 'ThisTypedComponentOptionsWithRecordProps<Vue, object, object, object, object>'.
Object literal may only specify known properties, and 'router' does not exist in type 'ThisTypedComponentOptionsWithRecordProps<Vue, object, object, object, object>'.
Overload 3 of 3, '(options?: ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>> | undefined): CombinedVueInstance<...>', gave the following error.
Argument of type '{ router: any; store: any; i18n: any; acl: any; render: (h: CreateElement) => VNode; }' is not assignable to parameter of type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'.
Object literal may only specify known properties, and 'router' does not exist in type 'ComponentOptions<Vue, DefaultData<Vue>, DefaultMethods<Vue>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'.
124 |
125 | Vue.config.productionTip = false;
> 126 | new Vue({router, store, i18n, acl, render: h => h(App)}).$mount('#app');
| ^
内部版本2:
ERROR in ~/node_modules/@aws-amplify/api-graphql/lib-esm/types/index.d.ts(3,21):
3:21 Cannot use namespace 'DocumentNode' as a type.
1 | import { DocumentNode } from 'graphql/language/ast';
2 | export interface GraphQLOptions {
> 3 | query: string | DocumentNode;
| ^
4 | variables?: object;
5 | authMode?: GRAPHQL_AUTH_MODE;
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env",
"jest"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx", "src/main.ts"
],
"exclude": [
"node_modules"
]
}
我将"skipLibCheck": true
添加到tsconfig.json文件中以解决构建问题2。这应该没问题,因为我们不想检查DocumentNode是否存在lib依赖关系。