Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class and slot properties errors in Vue 2.7 without @types/react dependency #1534

Closed
LurkingExorcist opened this issue Jul 4, 2022 · 2 comments · Fixed by #1533
Closed
Assignees

Comments

@LurkingExorcist
Copy link

In order to solve this issue as fast as possible, I created a small repo to reproduce the problem: https://github.com/Hope410/slot-class-issue

  1. Volar throws the error of class property doesn't exist in vue component defined by defineComponent function:
    Property 'class' does not exist on type 'IntrinsicAttributes & Readonly<Partial<{}> & Omit<{} & {}, never>>'.
    image

I've tried to fix the error by providing a type of class property in IntrinsicAttributes interface in jsx.d.ts file, and the problem has gone, but seems like the solution must be provided by Volar itself.

declare namespace JSX {
  interface IntrinsicAttributes {
    class?: any;
  }
}
  1. The next problem is about property 'slot':
    Property 'slot' does not exist on type 'ElementAttrs<HTMLAttributes>'.
    image

I've tried to solve this as well as class-property problem, but it didn't help. VS Code shows that property exists in JSX.IntrinsicAttributes interface, but compiler still throws the same.

Extending HTMLAttributes interface in declaration of vue/types/jsx module in jsx.d.ts file didn't fix the error. But direct extension of HTMLAttributes interface in node_modules/vue/types/jsx.d.ts helped.

@xiaoxiangmoe xiaoxiangmoe self-assigned this Jul 4, 2022
@NikhilVerma
Copy link

I have the same issue with data-* attributes.

<template>
   <div :data-selected="selected"></div>
</template>

Results in

Type '{ dataSelected: boolean; "data-selected": boolean; }' is not assignable to type 'ElementAttrs<HTMLAttributes>'.
  Property 'dataSelected' does not exist on type 'ElementAttrs<HTMLAttributes>'.ts(2322)

@NikhilVerma
Copy link

NikhilVerma commented Jul 6, 2022

Here is my solution

shims.d.ts

declare module "vue/types/jsx" {
	export interface HTMLAttributes {
		[key: `data${any}`]: any;
		[key: `aria${any}`]: string;
	}
}

export {};

@johnsoncodehk johnsoncodehk linked a pull request Jul 6, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants