What are the steps for incorporating TypeScript into a project created with Vue CLI@3?

td;dr How can I integrate vue-apollo into an existing TypeScript project?

I initialized a new Vue project using vue cli@3 with TypeScript.

Afterwards, I installed the vue-apollo plugin which automatically updated my main.ts file to include

apolloProvider: createProvider(),

during the creation of the Vue instance. However, this resulted in compiler errors.

Argument of type '{ router: VueRouter; store: Store<{}>; apolloProvider: { provide: () => {}; }; render: (h: CreateElement) => VNode; }' is not assignable to parameter of type 'ComponentOptions, DefaultMethods, DefaultComputed, PropsDefinition>, Record>'.

The object literal can only specify known properties, and 'apolloProvider' is not recognized in type 'ComponentOptions, DefaultMethods, DefaultComputed, PropsDefinition>, Record>'. [2345]

I noticed that there are type definitions in the types directory of the vue-apollo package I installed from npm, but I'm unsure how to utilize them.

Additionally, I encountered the following error:

[ts] Could not find a declaration file for module '@/vue-apollo'. '/Users/praveen/code/voicezen/repos/voicezen-ui/src/vue-apollo.js' implicitly has an 'any' type. [7016]

regarding the import statement in main.ts

import { createProvider } from '@/vue-apollo';

This issue might be related to the noImplicitAny rule, however changing the generated vue-apollo.js to vue-apollo.ts did not resolve the problems.

Switching it to .ts removed the compiler errors in main.ts related to the aforementioned issues, but triggered another problem.

Could not find a declaration file for module 'vue-cli-plugin-apollo/graphql-client'. '/Users/praveen/code/voicezen/repos/voicezen-ui/node_modules/vue-cli-plugin-apollo/graphql-client/index.js' implicitly has an 'any' type.

for

import {
  createApolloClient,
  restartWebsockets
} from 'vue-cli-plugin-apollo/graphql-client';

To address this, I could add a module declaration in my typings as follows, but I am uncertain if this is the correct approach.

declare module 'vue-cli-plugin-apollo/graphql-client';

The onLogin or onLogout method's parameter apolloClient, in the generated vue-apollo.ts also starts showing implicit any type warnings.

Answer №1

You're heading in the right direction, simply swap out vue-apollo.js with .ts

Next, include 'vue-cli-plugin-apollo' into types within 'tsconfig'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The stream.write function cannot be executed as a callable expression

Struggling to create a function that accepts either a writable stream (createWriteStream) or process.stdout/.stderr in TypeScript, but encountering an error. import { createWriteStream, WriteStream } from 'fs' const writehello = (stream: NodeJS. ...

Incorporate a header token into axios requests following a successful login action within vuex

I have successfully built a login system using Laravel Passport, but I am facing an issue when trying to add the header token to Axios requests. I have included the following code in my ProjectEmploye.vue file: created(){ axios.defaults.headers.common[" ...

Vue Testing Utilities - issue with data not updating upon click event activation

I recently created a basic test using Vue Test Utils: import { mount } from '@vue/test-utils' const App = { template: ` <p>Count: {{ count }}</p> <button @click="handleClick">Increment</button> `, ...

The localhost on port 3000 seems to be malfunctioning on Windows when trying to develop a ReactJS app using Create React App

For the past few days, I have been encountering a few issues that I have been trying to resolve without success. I attempted to stop localhost:3000 with netstat -ano | findstr :3000 taskkill /PID myPIDhere /F Despite my efforts, I still see- TCP 0. ...

What is the recommended way to use the async pipe to consume a single Observable property in a view from an Angular2

Suppose I have a component with the following property: import { Component, OnInit } from 'angular2/core'; import { CarService } from 'someservice'; @Component({ selector: 'car-detail', templateUrl: './app/cars/ ...

Vue: Choosing an option during the execution of setInterval

I'm facing an issue where I can't select an option while a setInterval function is running on the page. The main problem is that an option cannot be selected at the same time as the setInterval timer fires. let updateDelay = 100; var vueObj = ...

Convert checkbox choices to strings stored in an array within an object

I have a intricate object structure JSON{ alpha{ array1[ obj1{}, obj2{} ] } } In addition to array1, I need to include another array: array2 that will only consist of strin ...

Determine the category of a nested key within a different type

I'm currently utilizing graphql-codegen which generates types in the following structure: type Price = { onetime: number; monthtly: number; }; type CarModel = { price: Price; name: string; }; type Car = { model: CarModel; someOtherAttri ...

Validating a single field name with various DTO types based on conditions in a NestJS application

There is a field named postData in EmailTypeDto, but it has different types based on conditions. It may be confusing to explain in words, but the code makes it clear. export class EmailTypeDto { @IsEnum(EmailType) public type: EmailType; @ValidateIf ...

I am unable to utilize autocomplete with types that are automatically generated by Prisma

Currently, I am working on a project utilizing Next and Prisma. Within my schema.prisma file, there are various models defined, such as the one shown below: model Barbershop { id String @id @default(uuid()) name String address String ...

Angular displays incorrect HTTP error response status as 0 instead of the actual status code

In Angular, the HttpErrorResponse status is returning 0 instead of the actual status. However, the correct status is being displayed in the browser's network tab. ...

Employing square bracket notation based on the input data

I'm currently in the process of enhancing some code within my library, but I've encountered a perplexing issue with bracket notation not functioning as expected when attempting to call an imported class. The parameter type expects a camelCased s ...

rxjs5 - the WebSocket constructor is missing

I can't seem to figure out this basic task. I'm attempting to create an Observable from rxjx/observable/dom/webSocket in RxJS5, but I'm not using typescript, or es6 modules... just plain 'ole good commonJS. Despite following the documen ...

Directly within Angular, map the JSON data to an object for easy assignment

I came across this information on https://angular.io/guide/http. According to the source, in order to access properties defined in an interface, it is necessary to convert the plain object obtained from JSON into the required response type. To access pr ...

Error: Angular 2 - Node - gulp | Unable to locate module .component

I'm in the process of developing a complete TypeScript application with Node.js in TypeScript that is intended to be used with Angular 2 and built using Gulp as the build tool. The Gulp task successfully compiles all files from /src to /dist, convert ...

Endpoint path for reverse matching in Mongodb API

I am currently in the process of setting up a webhook system that allows users to connect to any method on my express server by specifying a method and an endpoint to listen to (for example PUT /movies/*). This setup will then send the updated movie to the ...

Can you set up a mechanism to receive notifications for changes in an array variable in Angular?

I'm exploring methods to delay an HTTP request until the user stops interacting. I am considering using the debounceTime() operator from RxJs, but I need this to be triggered by changes in an array that I have defined. Here is the scenario: export c ...

The types 'X' and 'string' do not intersect

I have a situation where I am using the following type: export type AutocompleteChangeReason = | 'createOption' | 'selectOption' | 'removeOption' | 'clear' | 'blur'; But when I try to compress the cod ...

Issue arises when the value becomes nonexistent following the execution of a

Having an issue with my code where I have one class with a function in it, and another class that imports the first class to use that function. However, after the function is executed, I am not getting the expected value. First class: export class MoveE ...

Tips for implementing a personalized Circuit Breaker in Node.js that monitors request volume

Currently, I am exploring the most effective way to implement a circuit breaker based on the number of requests served in a Typescript/express application rather than fail percentage. Given that the application is expected to accommodate a large volume of ...