TypeScript 构建错误

TypeScript build errors

我正在尝试将 Vuejs 应用程序转换为增量使用 Typescript 并面临几个构建问题。应用程序的 package.json 显示 "@vue/cli-plugin-typescript": "^4.3.1", "typescript": "^3.5.2",

我能够通过以下方式解决几个构建问题 一个。创建 .d.ts 文件 例如:我通过使用 declare module 'vue-tour';

创建 vue-tour.d.ts 文件修复了 main.ts 中与 import VueTour from '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})

我如何创建 .d.ts 文件来修复构建问题,而不是使用 // @ts-ignore

我还有与 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 依赖项。