Can anyone provide guidance on resolving the ts(2305) error in a Vue3 TypeScript project?

declare module '*.vue' {
  import type { DefineComponent } from 'vue' // The module "../node_modules/vue/dist/vue" does not have an exported member “DefineComponent”.ts(2305)
  const component: DefineComponent<{}, {}, any>
  export default component
}

declare module '@vue/runtime-core' {
  export interface ComponentCustomProperties {
      $goto: any
  }
}

Why am I receiving this error message? I am unsure of how to resolve it. Can someone help?

Answer №1

To implement the new declaration, it should be placed in the main.ts file

@Zenthae - https://github.com/vuejs/vue-next/pull/982#issuecomment-787105294

The declaration statements seem to only take effect when included in a ts file rather than a .d.ts file. For example:

src/shim-vue.d.ts

declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}

src/main.ts

import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')

// Placing it here or in any other `.ts` file works
declare module '@vue/runtime-core' {
  export interface ComponentCustomProperties {
      $goto: any
  }
}

Extracted From Vue Documentation

This information has also been included in the Vue documentation.

Refer to: https://v3.vuejs.org/guide/typescript-support.html#augmenting-types-for-globalproperties (Added in vuejs/docs-next#723)

Ensure Declaration File is a TypeScript Module

To make use of module augmentation, it's important to have at least one top-level import or export statement in your file, even if it's just export {}.

In TypeScript, any file with a top-level import or export is considered a 'module'. Declarations made outside of a module will overwrite original types instead of augmenting them.

Answer №2

When using a global declare module, it's important to note that it will overwrite the original declaration. This means that if you are using module "@vue/runtime-core", it will override the declaration for "vue", which depends on "@vue/...". This can result in an error.

To avoid this issue, the correct approach is to place the declaration "declare module '@vue/runtime-core'" in a separate .d.ts file.

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

Updating non-data properties dynamically in a custom AG Grid cell renderer

In my grid setup, I have implemented an editor button in a column for each row and a new item creator button outside the grid. One of the requirements is that all buttons should be disabled when either the create or edit button is clicked. To achieve thi ...

Retrieve two pieces of data from the Laravel API

I have two types of data coming from an API: 1. Category Food 2. Finished Goods How can I display both sets of data on one Vue page? Currently, I am only able to display data from one API. This is my attempted code: export default { data(){ items:[ ...

Discovering the method to access item values within a loop in Vue.js

Issue: I'm currently grappling with how to transfer the value of a selected item to another component Explore the codepen: https://codepen.io/anon/pen/zRXBNY Within the codepen menu, an item is activated by a right click Imagine we have a loop (th ...

Dealing with Typescript Errors in Ionic3: How to Handle "Property 'x' does not exist on value of type 'y'" Issues

I stumbled upon this particular post (and also this one) while searching for a solution to my issue. I am looking to suppress these specific errors: 'Payload' property is missing from the 'Matatu' type. 'Key' property is no ...

Set a value to the field name within a variable in TypeScript

Can anyone help me with this problem? type A { f1: string; f2; string; } I have a variable that holds the name of a field: let fieldName: string = "f2"; I want to create an object using the fieldName: {"content of fieldName": "sdf"} Any suggestio ...

Vue's emission system, accessed through this.$emits, unexpectedly ceases functioning mid-function call

Within my Vue frontend, I have a function designed to emit updates to the parent component before and after sending a request to the server. The function in question is as follows: saveUpdates: async function () { const component = { doc: ...

The 'import.meta' meta-property can only be used with the '--module' set to 'es2020', 'esnext', or 'system'.ts(1343)

Whenever I attempt to utilize import.meta.url (as demonstrated in the Parcel docs), I am consistently met with the error message "The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es ...

Managing data, functions, and tasks consistently in an Electron-based React application despite navigating through various components - how to do it effectively?

As a newcomer to React, I have encountered several challenges while trying to implement certain features. Currently, I am working on an application that consists of a grid view and details view. Initially, I used props and functions to manipulate the state ...

Exploring Typescript keyof in Storybook's User Interface customizations

Currently, I am working on developing components for integration with Storybook, but I am encountering an issue related to Typescript inferred types. While striving for code reusability, I prefer not to specify the options for a control within the story i ...

Comparison of valueChanges between ReactiveForms in the dom and component级主动形

Is there a method to determine if the change in valueChanges for a FormControl was initiated by the dom or the component itself? I have a scenario where I need to execute stuff() when the user modifies the value, but I want to avoid executing it if the v ...

Sharing precise API information between React components in React Components

I am currently learning react and facing an issue with sending data to other component files. I am trying to verify a user login from a backend API within an if statement, and if successful, I want to send the user ID to another component file. However, ...

React: Issue with Intersection Observer not triggering state updates

Looking to implement an endless scroll feature using intersection observer, where new content appears as the user reaches the bottom. Here's a simplified version of the code: function App() { const ids = [1, 2, 3, 4, 5, 6] const [ProductIds, setPr ...

Avoiding an endless spiral on a setter in JavaScript/TypeScript

Implementing TypeScript, I've been working on setting up a concept called a "trigger" : an object that includes both a checker function (which returns a Boolean) and a behavior function capable of performing various tasks. My aim is to execute the che ...

Vue Project Encounters Issues with router-link and router-view in the Boilerplate Setup

After using the command vue create to set up a new Vue project with Babel, TypeScript, Router, and Unit Testing, I proceeded to install axios via npm. With no additional modifications made, I attempted to run the application by navigating to the src direc ...

The Vue application combined with TypeScript is displaying an empty white screen

I've enrolled in a Vue + Firestore course, but I'm attempting to use TypeScript instead of conventional JavaScript. The basic setup is complete, however, my app displays a blank page when it should be showing a simple header text from the App.vue ...

Retrieving decimal value from a given string

Currently, I am working with Google Maps and encountering an issue with distance values being returned as strings like 1,230.6 km. My goal is to extract the floating number 1230.6 from this string. Below is my attempted solution: var t = '1,234.04 km ...

The Typings installation is malfunctioning when attempting to set up TypeScript definitions that have already been

I am facing an issue with my typings.json file which contains declarations for the typescript definitions needed in my project. The reference can be found below: ... "ambientDependencies": { "bluebird": "registry:dt/bluebird#2.0.0+20160319051630", ...

Having difficulty converting string columns/data to numerical values when exporting an Ag-Grid table to Excel with getDataAsExcel function

I am having an issue with exporting data from my ag-grid table to excel using the API method getDataAsExcel. The problem arises because I have a column containing only string values, while all other columns are numeric and displayed in the ag-grid table a ...

Manifest JSON not displaying Add to Home Screen prompt

I am trying to implement the prompt for adding to the home screen using manifest.json, but I am facing an issue where the prompt is not showing up even though my PWA score in the audit is 100%. Below is the structure of my dist folder: https://i.sstatic. ...

Guide to implementing an enum in an Angular Component

Having a global state (or "mode") in my Angular Components is leading me to look for more efficient ways to code. Here is what I have tried: @Component({ .... }) export class AbcComponent implements OnInit { enum State { init, view, edit, cre ...