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

ConfirmDialog onHide type definition doesn't match runtime behavior #7684

Closed
reponemec opened this issue Feb 7, 2025 · 4 comments · Fixed by #7685 or #7695
Closed

ConfirmDialog onHide type definition doesn't match runtime behavior #7684

reponemec opened this issue Feb 7, 2025 · 4 comments · Fixed by #7685 or #7695
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

@reponemec
Copy link

ConfirmDialog onHide type definition doesn't match runtime behavior

The type definition for ConfirmDialog's onHide callback doesn't match its runtime behavior.

According to confirmdialog.d.ts, onHide is defined as:

onHide: (result: string) => void

However, at runtime, the callback receives an array containing an object with a result property:

[{ result: 'cancel' | 'accept' | 'reject' }]

This causes TypeScript errors when trying to properly type the onHide callback handler.

To reproduce:

interface ConfirmDialogHideEvent {
    result: 'cancel' | 'accept' | 'reject';
}

confirmDialog({
    onHide: (event: ConfirmDialogHideEvent[]) => {  // TypeScript error here
        if (event[0]?.result === 'cancel') {
            // handle dialog close
        }
    }
});

Current workaround:

// @ts-ignore - PrimeReact ConfirmDialog has incorrect type definition - onHide returns [{result: 'cancel' | 'accept' | 'reject'}] instead of string
onHide: (event: ConfirmDialogHideEvent[]) => {
    if (event[0]?.result === 'cancel') {
        // handle dialog close
    }
}

Expected behavior:
The type definition should match the actual runtime behavior.

Environment:
"primereact": "^10.8.3"
"react": "^18.3.1"
"typescript": "^5.2.2"

@github-actions github-actions bot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 7, 2025
@melloware melloware added Typescript Issue or pull request is *only* related to TypeScript definition and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Feb 7, 2025
@melloware melloware self-assigned this Feb 7, 2025
@melloware melloware added this to the 10.9.3 milestone Feb 7, 2025
melloware added a commit to melloware/primereact that referenced this issue Feb 7, 2025
@melloware
Copy link
Member

@reponemec i submitted a PR to fix it so it actually returns the type matching the Typescript it should just be a single string "accept" or "reject". It should not be an ARRAY.

@melloware melloware added the Type: Bug Issue contains a defect related to a specific component. label Feb 7, 2025
@reponemec
Copy link
Author

reponemec commented Feb 12, 2025

After updating to PrimeReact version 10.9.2, I've observed that the type of the result parameter in the onHide handler of the ConfirmDialog component varies depending on how the dialog is closed:

  • "YES" button: [{ result: "accept" }]
  • "NO" button: [{ result: "reject" }]
  • "Esc" key: [{ result: KeyboardEvent }]
  • "X" button: [{ result: SyntheticBaseEvent }]

Is this behavior intentional and final?

@melloware
Copy link
Member

No that is not intentional it should be a single string of either 'cancel' | 'accept' | 'reject' let me make sure ESC and X button both are handled correctly.

@melloware
Copy link
Member

@reponemec thanks for the report just submitted PR to fix ESC/Close to report 'cancel'

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
2 participants