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

showNotification doesn't support data-* attributes #5640

Closed
1 of 2 tasks
OrRosenblatt opened this issue Jan 26, 2024 · 2 comments · Fixed by #7097
Closed
1 of 2 tasks

showNotification doesn't support data-* attributes #5640

OrRosenblatt opened this issue Jan 26, 2024 · 2 comments · Fixed by #7097
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@OrRosenblatt
Copy link

OrRosenblatt commented Jan 26, 2024

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.4.2

What package has an issue?

@mantine/notifications

What framework do you use?

Vite

In which browsers you can reproduce the issue?

Not applicable – issue is not related to the browser

Describe the bug

When passing data-* attributes to showNotification or notifications.show functions a TS error is thrown:

Argument of type '{ message: string; "data-<attribute>": string; }' is not assignable to parameter of type 'NotificationData'.
  Object literal may only specify known properties, and '"data-<attribute>"' does not exist in type 'NotificationData'.

Example:
data attribute used in show notification caused TS error

See link below for example code.

If possible, include a link to a codesandbox with a minimal reproduction

https://codesandbox.io/p/sandbox/focused-moon-m85ccq

Possible fix

No response

Self-service

  • I would be willing to implement a fix for this issue
rtivital added a commit that referenced this issue Feb 1, 2024
@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Feb 1, 2024
@rtivital
Copy link
Member

rtivital commented Feb 9, 2024

Fixed in 7.5.2

@rtivital rtivital closed this as completed Feb 9, 2024
@twiddler
Copy link
Contributor

This change breaks this (simplified) code:

import { NotificationData, notifications } from '@mantine/notifications'

type OneTimeNotificationProps = Omit<NotificationData, 'color'>

function showSuccessNotification(props: OneTimeNotificationProps) {
    notifications.show({ // Argument of type '{ color: "green"; icon: JSX.Element; }' is not assignable to parameter of type 'NotificationData'. Property 'message' is missing in type '{ color: "green"; icon: JSX.Element; }' but required in type 'NotificationData'. ts(2345)
        color: 'green',
        ...props,
    })
}

TypeScript can no longer infer OneTimeNotificationProps narrowly:

type OneTimeNotificationProps = {
    [x: string]: any;
    [x: number]: any;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants