Vue 3 and Typescript "Property does not exist on type" error with augmented ComponentCustomProperties and data key on component.
See original GitHub issueInfo
- 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:
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:
- Created 3 years ago
- Reactions:8
- Comments:14 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my case I needed this in my
tsconfig.json
: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.