question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Vue 3 and Typescript "Property does not exist on type" error with augmented ComponentCustomProperties and data key on component.

See original GitHub issue
  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: macOS
  • Vetur version: v0.28.0
  • VS Code version: 1.50.0

Problem

This is my vue-shims.d.ts where I add the type for a global property I’ve added.

import { ComponentCustomProperties } from "vue";
import { CONSTANTS } from "@constants";

declare module "@vue/runtime-core" {
  interface ComponentCustomProperties {
    $const: typeof CONSTANTS;
  }
}

This works fine until I add a data option to my component, see screen shots of with and without:

Screenshot 2020-10-10 at 20 57 31 Screenshot 2020-10-10 at 20 57 44

When I add the data option, Vetur thinks $const does not exist on “this”, as if what’s in data overwrites my augmented ComponentCustomProperties.

Typescript is still getting the type inference as you can see from the cropped off bit of the image with the error so I think this is just a vetur issue.

Reproducible Case

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:8
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

50reactions
catherinelusecommented, Oct 29, 2021

In my case I needed this in my tsconfig.json:

"noImplicitThis": false,
4reactions
nrgnrgcommented, Oct 11, 2020

Sure I’ll do that asap.

I’ve found a workaround for now, annotating return type of the computed property removed the error but threw a line 0 “cannot read property ‘map’ of undefined” in eslint. Upgraded @typescript-eslint/eslint-plugin and @typescript-eslint/parser to the latest version but I had to disable the @typescript-eslint/camelcase rule. It seems to have fixed the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript - Vue js 3 - Property 'projects' does not exist on type ...
I had a similar issue with Vetur errors on computed properties, and search brought this issue up. According to this link, this is...
Read more >
‍♂️ ‍♀️ Vue 3 error with using TypeScript: property X does ...
vue :4:54 - error TS2339: Property 'value' does not exist on type 'EventTarget'. 4 @input="$emit('update:modelValue', $event.target.value) ...
Read more >
[Solved]-Vue js 3 - Property 'projects' does not exist on type ...
The problem with my project now was that only the components registered globally were not correctly recognized by either vetur or volar, so...
Read more >
TypeScript with Options API - Vue.js
Type inference for props in Options API requires wrapping the component with defineComponent() . With it, Vue is able to infer the types...
Read more >
declare module '@vue/runtime-core' - You.com - You.com
You can augment the @vue/runtime-core TypeScript module in your application: ... Vue.js 3 and typescript : Property '$store' does not exist on type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found