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

The typescript type definition have some problems. #6060

Open
ccqgithub opened this issue Jul 15, 2024 · 2 comments
Open

The typescript type definition have some problems. #6060

ccqgithub opened this issue Jul 15, 2024 · 2 comments
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@ccqgithub
Copy link

ccqgithub commented Jul 15, 2024

Describe the bug

(Vscode with Volar)

  1. When I import compoents by an alias name, there are no type hinting for props.

There are no type hinting for this.

import PButton from 'primevue/button';

But this is ok.

import Button from 'primevue/button';
  1. Type declaration conflict.

When I import components, it will load the following global type declaration, which will pollute other component's types.

declare module 'vue' {
    export interface GlobalComponents {
        Button: GlobalComponentConstructor<ButtonProps, ButtonSlots, ButtonEmits>;
    }
}

For example, when I import Button of primeVue, the other Button in template that not import from primevue will be polluted.

Reproducer

https://stackblitz.com/edit/primevue-4-ts-vite-issue-template-j7eglm?file=src%2FApp.vue

PrimeVue version

4.0.0

Vue version

3.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@ccqgithub ccqgithub added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 15, 2024
@ccqgithub
Copy link
Author

ccqgithub commented Jul 15, 2024

For problem 1, when I change DefineComponent from @primevue/core to vue, the problem fixed.

import type { DefineComponent } from '@primevue/core';

declare const Button: DefineComponent<ButtonProps, ButtonSlots, ButtonEmits>;

to

import type { DefineComponent } from 'vue';

declare const Button: DefineComponent<ButtonProps, ButtonSlots, ButtonEmits>;

@i7slegend
Copy link
Contributor

i7slegend commented Jul 17, 2024

For problem 1, when I change DefineComponent from @primevue/core to vue, the problem fixed.

import type { DefineComponent } from '@primevue/core';

declare const Button: DefineComponent<ButtonProps, ButtonSlots, ButtonEmits>;

to

import type { DefineComponent } from 'vue';

declare const Button: DefineComponent<ButtonProps, ButtonSlots, ButtonEmits>;

Do this you fix only for props. Slots and emits doesn't work anyway.

I found what vue DefineComponent typescript type uses first generic (which is ButtonProps in this case) for another type guards. So, i think fix this issue is replace in @primevue/core type guard DefineComponent:
from

export type DefineComponent<P = {}, S = {}, E = {}, M = {}> = _DefineComponent<P, {}, {}, {}, M & MethodOptions, {}, {}, E & ObjectEmitsOptions, string, {}, {}, {}, S & SlotsType>;

to:

export type DefineComponent<P = {}, S = {}, E = {}, M = {}> = _DefineComponent<P, {}, {}, {}, M & MethodOptions, {}, {}, E & ObjectEmitsOptions, string, PublicProps, Readonly<ExtractPropTypes<P>>, ExtractDefaultPropTypes<P>, SlotsType<S>>;

It require types PublicProps, SlotsType, ExtractDefaultPropTypes, ExtractPropTypes from vue bundle

But i think need to use defineComponent (from primevue team side) in vue files by vue's typescript guide: https://vuejs.org/guide/typescript/overview#definecomponent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

2 participants