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

ConfirmationDialog: throws TS error in prod build #2953

Closed
michalbujalski opened this issue Jun 2, 2022 · 6 comments
Closed

ConfirmationDialog: throws TS error in prod build #2953

michalbujalski opened this issue Jun 2, 2022 · 6 comments
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component. Typescript Issue or pull request is *only* related to TypeScript definition
Milestone

Comments

@michalbujalski
Copy link

Describe the bug

When using ConfirmationDialog and running yarn build the following error is thrown:

$ tsc && vite build
node_modules/primereact/confirmdialog/confirmdialog.d.ts:25:18 - error TS2430: Interface 'ConfirmDialogProps' incorrectly extends interface 'Omit<DialogProps, "onHide">'.
  Types of property 'footer' are incompatible.
    Type 'ConfirmDialogTemplateType' is not assignable to type 'DialogTemplateType'.
      Type '(options: ConfirmDialogOptions) => ReactNode' is not assignable to type 'DialogTemplateType'.
        Type '(options: ConfirmDialogOptions) => ReactNode' is not assignable to type '(props: DialogProps) => ReactNode'.
          Types of parameters 'options' and 'props' are incompatible.
            Type 'DialogProps' is missing the following properties from type 'ConfirmDialogOptions': accept, reject, acceptClassName, rejectClassName, and 4 more.

25 export interface ConfirmDialogProps extends Omit<DialogProps, 'onHide'> {

Changing:

export interface ConfirmDialogProps extends Omit<DialogProps, 'onHide'> {
...
    footer?: ConfirmDialogTemplateType;
...
}

to:

export interface ConfirmDialogProps extends Omit<DialogProps, 'onHide'> {
...
    footer?: DialogTemplateType;
...
}

seems to fix the issue

Reproducer

No response

PrimeReact version

8.0.0

React version

18.x

Language

TypeScript

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

yarn build gives out typescript error



Expected behavior

No response

@michalbujalski michalbujalski added the Type: Bug Issue contains a defect related to a specific component. label Jun 2, 2022
@melloware melloware added Typescript Issue or pull request is *only* related to TypeScript definition and removed Type: Bug Issue contains a defect related to a specific component. labels Jun 2, 2022
@melloware
Copy link
Member

Hmmm but that doesn't seem correct. When you use a footer it passes it ConfirmDialogOptions

interface ConfirmDialogOptions {
    accept(): void;
    reject(): void;
    acceptClassName: string;
    rejectClassName: string;
    acceptLabel: string;
    rejectLabel: string;
    element: React.ReactNode;
    props: ConfirmDialogProps;
    [key: string]: any;
}

Which is not a DialogProps so you would not be getting the correct values passed into your function if you change the signature that way?

@melloware melloware changed the title Component: ConfirmationDialog throws TS error in prod build ConfirmationDialog: throws TS error in prod build Jun 2, 2022
@melloware
Copy link
Member

OK I think the issue needs to be fixed a different way. Can you just try changing this line...

type ConfirmDialogTemplateType = React.ReactNode | ((options: ConfirmDialogOptions) => React.ReactNode) 

to...

type ConfirmDialogTemplateType = React.ReactNode | ((options: ConfirmDialogOptions) => React.ReactNode) | ((props: ConfirmDialogProps) => React.ReactNode);

@michalbujalski
Copy link
Author

Tired it. Still getting the same error

@Ruan20795
Copy link
Contributor

Ruan20795 commented Jun 3, 2022

@melloware @michalbujalski having the same issue so created a PR where I changed it to

type ConfirmDialogTemplateType = React.ReactNode | ((props: ConfirmDialogProps) => React.ReactNode);

and removed the ConfirmDialogOptions since it does not seem to be used

@melloware
Copy link
Member

@Ruan20795 I made comments on your PR. Your PR won't fix the issue.

@melloware melloware linked a pull request Jun 20, 2022 that will close this issue
@melloware melloware added this to the 8.2.0 milestone Jun 20, 2022
@mertsincan
Copy link
Member

Hi,

Sorry for the delayed response! Could you please try #2959 (comment)?

@mertsincan mertsincan added Status: In Progress Core Team is working on the issue or pull request Type: Bug Issue contains a defect related to a specific component. and removed Status: In Progress Core Team is working on the issue or pull request labels Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component. Typescript Issue or pull request is *only* related to TypeScript definition
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants