I am trying to convert a Vuejs application to incrementally use Typescript and facing several build issues. The application's package.json shows "@vue/cli-plugin-typescript": "^4.3.1", "typescript": "^3.5.2",
I was able to fix a couple of build issues by
a. creating .d.ts
file eg: I fixed build error related to import VueTour from 'vue-tour';
in main.ts
by creating a vue-tour.d.ts
file with declare module 'vue-tour';
b. adding // @ts-ignore
before the build line error. eg:
// @ts-ignore
import axios from "./axios.js";
~\src\axios.js
import axios from 'axios'
const domain = ""
export default axios.create({domain})
Instead of using // @ts-ignore
, how can I create a .d.ts
file to fix the build issue?
I also have build errors related to types generated by AWS Amplify and a custom router instance that we use.
What is the recommended way to solve these build issues?
~\src\router.js
import Vue from 'vue';
import Router from 'vue-router';
Vue.use(Router);
const router = new Router({............
});
export default router;
build issue 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');
| ^
build issue 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"
]
}
I added the "skipLibCheck": true
to the tsconfig.json file to fix build issue 2. This should be ok as we do not want to check DocumentNode for lib dependencies.