What are the steps to establishing a Vue 3 TypeScript Plugin?

I am currently in the process of developing a new Plugin for Vue 3 using Typescript.

Here is an overview of my code:

//somePlugin
import { App, Plugin } from "vue";

const somePlugin: Plugin = {
  install: async (app: App, options: {...}): Promise<void> => {
    ....
  }
}
export { somePlugin };
//----------------------------------------------------------
//main.ts
import { somePlugin } from "@/plugins/somePlugin";
import App from "./App.vue";

const app = createApp(App);
app.use(somePlugin);

Despite my efforts, I encountered the following Error:

Cannot find module '@/plugins/somePlugin' or its corresponding type declarations.ts(2307)

As someone who is relatively new to Typescript, my understanding was that "somePlugin" should be well-defined due to its association with the Vue internal "Plugin."

Upon exploring solutions provided for similar issues, I attempted creating a "somePlugin.d.ts" file, but was uncertain about what exactly to declare within. My initial attempt looked like this:

declare module "somePlugin";

Unfortunately, this approach did not yield the desired results. As such, I am seeking guidance on how to properly declare the Plugin so it can function without resorting to using ts-ignore.

Answer ā„–1

Unfortunately, I must confess that the reason behind my situation was simply a misplaced hyperlink.

Answer ā„–2

It appears that the issue may lie within your tsconfig.json (Typescript configuration) file. I recently set up a new vue 3 project and encountered no problems. Here is the contents of the tsconfig.json file from my freshly created project:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env"
    ],
    "paths": {
      "@/": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

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

Executing functions in Vue TypeScript during initialization, creation, or mounting stages

Just a few hours ago, I kicked off my Vue TypeScript project. I've successfully configured eslint and tslint rules to format the code as desired, which has left me quite pleased. Now, I'm curious about how to utilize the created/mounted lifecycl ...

A guide on how to bring a TypeScript class into another TypeScript class

I find myself struggling more than necessary with this task. Working with Ionic 3/Angular, I began creating a component and realized it wasn't exactly what I needed. Essentially, the class simply triggers an Ionic popup and, if the user clicks ' ...

Can you explain the significance of the angle brackets "<>" in a Typescript function declaration?

When working with TypeScript code, I often come across code enclosed in angle brackets, similar to HTML. Despite knowing that they are not HTML elements, and understanding that the content within the angle brackets represents types, I frequently encounter ...

Ionic app: refresher functionality works in browser but not on iOS home screen app

I am currently developing a Progressive Web App (PWA) using Ionic, and I have implemented an ion-refresher in the app: <ion-content> <ion-refresher slot="fixed" (ionRefresh)="refresh()"> <ion-refresher-content pullingIcon="lines">& ...

Using InjectionToken results in the generation of the error message "Encountered an issue while resolving symbol values

Recently, I encountered an issue while building my Ionic 3 app using ionic cordova build ios --prod. Everything was functioning perfectly until a package update caused some complications, preventing me from successfully building the app. I suspect that t ...

Steps to converting an enum or literal

Hey there, I'm relatively new to working with TypeScript and I've been experimenting with transforming enums/literals using functions. For instance, creating a capitalize function that capitalizes the first letter of a string. (e.g., mapping typ ...

utilize Angular's interface-calling capabilities

In the backend, I have an interface structured like this: export interface DailyGoal extends Base { date: Date; percentage: number; } Now, I am attempting to reference that in my component.ts file import { DailyGoal } from '../../interfaces' ...

Identifying imports from a barrel file (index.ts) using code analysis

Can anyone help me understand how the Typescript compiler works? I am trying to write a script that will parse each typescript file, search for import declarations, and if an import declaration is using a barrel-file script, it should display a message. Af ...

The upcoming development does not involve creating an entire HTML webpage using on-demand static site generation (SS

Iā€™m encountering a problem when utilizing getStaticPaths and getStaticProps to create an on-demand SSG for a sharing page. My setup involves Next v12.1.0 and React 17.0.2. After building a specific /[id] page, I can retrieve the data but the HTML output ...

The process of removing and appending a child element using WebDriverIO

I am trying to use browser.execute in WebDriverIO to remove a child element from a parent element and then append it back later. However, I keep receiving the error message "stale element reference: stale element not found". It is puzzling because keepin ...

Encountering the error message "Uncaught Promise (SyntaxError): Unexpected end of JSON input"

Below is the code snippet I am using: const userIds: string[] = [ // Squall '226618912320520192', // Tofu '249855890381996032', // Alex '343201768668266496', // Jeremy '75468123623614066 ...

Implementing a NestJs application on a microcomputer like a Raspberry Pi or equivalent device

I'm facing a challenge in trying to find a solution for what seems like a simple task. I am aware that using the Nest CLI, I can utilize the command "nest build" to generate a dist folder containing the production files of my project. However, when I ...

Find out if a dynamically imported component has finished loading in Nextjs

Here is a simplified version of my current situation import React, { useState } from 'react'; import dynamic from 'next/dynamic'; const DynamicImportedComponent = dynamic(() => import('Foo/baz'), { ssr: false, loading ...

Ways to enhance TypeScript definitions for Node.js modules

Using the nodejs module "ws", I installed typings using typings i dt~ws import * as WebSocket from "ws"; function add(client:WebScoket){ let cid = client.clientId; } I am trying to Expand the WebSocket object with a property called clientId, but I&a ...

Bypassing disputes in a TypeScript function

I attempted to implement the solution provided by Pacerier in response to the question about skipping arguments in a JavaScript function. However, it doesn't seem to be working for me. The function I am dealing with has numerous arguments. this.servi ...

Enhancing Vue prop with TypeScript typing

In my Vue component, I am working with a prop called tabs. The format for this prop is expected to be as follows: [{ id: string title: string color: `#${string}` },{ id: string title: string color: `#${string}` }] Currently, I am utilizing Lar ...

Instructions on resolving the issue: The type 'string | ChatCompletionContentPart[] | null' cannot be assigned to type 'ReactNode'

I've been working on my first Saas App, similar to a ChatGPT, using NextJs with the OpenAI Api. Most of the development was based on a YouTube tutorial until I encountered two errors caused by an update in the OpenAI version. Despite trying various so ...

Is there a way to take a screenshot of a three.js scene with a WebXR API integration for an immersive augmented reality (AR) experience?

I am currently working on an augmented reality project that utilizes Three.js, WebXR, and Vue.js version 3. My objective is to incorporate a button that will take a snapshot of the existing scene when clicked. However, I am encountering challenges when att ...

No gripes about incorrect typing when extending interfaces

I tried out the following code snippet here interface OnlyName { name: string } interface MyTest2 extends OnlyName { age: number } let test1: OnlyName; const setTest1 = (v: OnlyName) => { test1 = v console.log(test1) } let test2: My ...

Error message: Failure to define class methods when exporting the class from a file

In my project, I have defined a class called BinarySearchTree in a file named a.js. This class has been exported and then imported into another file where it is used as the parent class for a different class called Traversal. However, I encountered an issu ...