-
Notifications
You must be signed in to change notification settings - Fork 65
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
Typescript support #29
Comments
I'd love to have support for typescript. |
add to tsconfig.json:
add to src/declaration.d.ts:
|
Hello guys, I've added these types for myself. Perhaps they can help you as well. Not sure if they are all right, but feel free to update them accordingly. declare module 'react-notifications' {
import { ReactNode } from 'react';
import { EventEmitter } from 'events';
enum NotificationType {
INFO = 'info',
SUCCESS = 'success',
WARNING = 'warning',
ERROR = 'error'
}
enum EventType {
CHANGE = 'change',
INFO = 'info',
SUCCESS = 'success',
WARNING = 'warning',
ERROR = 'error'
}
interface NotificationProps {
type: NotificationType,
title?: ReactNode,
message: ReactNode,
timeOut?: number,
onClick: () => any,
onRequestHide: () => any
}
interface NotificationsProps {
notifications: Notification[];
onRequestHide?: (notification: Notification) => any;
enterTimeout?: number;
leaveTimeout?: number;
}
interface NotificationContainerProps {
enterTimeout?: number;
leaveTimeout?: number;
}
interface INotificationManagerCreate {
type: EventType,
title?: NotificationProps['title']
message?: NotificationProps['message']
timeout?: number,
onClick?: () => any,
priority?: boolean
}
class Notification extends React.Component<NotificationProps, {}> {}
class Notifications extends React.Component<NotificationsProps, {}> {}
class NotificationContainer extends React.Component<NotificationContainerProps, {}> {}
class NotificationManager extends EventEmitter {
static create(INotificationManagerCreate) : void
static info(message?: INotificationManagerCreate['message'], title?: INotificationManagerCreate['title'], timeOut?: INotificationManagerCreate['timeout'], onClick?: INotificationManagerCreate['onClick'], priority?: INotificationManagerCreate['priority']) : void
static success(message?: INotificationManagerCreate['message'], title?: INotificationManagerCreate['title'], timeOut?: INotificationManagerCreate['timeout'], onClick?: INotificationManagerCreate['onClick'], priority?: INotificationManagerCreate['priority']) : void
static warning(message?: INotificationManagerCreate['message'], title?: INotificationManagerCreate['title'], timeOut?: INotificationManagerCreate['timeout'], onClick?: INotificationManagerCreate['onClick'], priority?: INotificationManagerCreate['priority']) : void
static error(message?: INotificationManagerCreate['message'], title?: INotificationManagerCreate['title'], timeOut?: INotificationManagerCreate['timeout'], onClick?: INotificationManagerCreate['onClick'], priority?: INotificationManagerCreate['priority']) : void
static remove(notification: Notification) : void
}
} |
@cristian-chis Where we need to add this file and how it will take, suggest me please |
You just need to add a custom typings ( Don't forget to restart the server afterwards! |
I suggest some minor changes after using the code: declare module 'react-notifications' {
import React ,{ ReactNode } from 'react';
import { EventEmitter } from 'events';
enum NotificationType {
INFO = 'info',
SUCCESS = 'success',
WARNING = 'warning',
ERROR = 'error'
}
enum EventType {
CHANGE = 'change',
INFO = 'info',
SUCCESS = 'success',
WARNING = 'warning',
ERROR = 'error'
}
interface NotificationProps {
type: NotificationType,
title?: ReactNode,
message: ReactNode,
timeOut?: number,
onClick: () => any,
onRequestHide: () => any
}
interface NotificationsProps {
notifications: Notification[];
onRequestHide?: (notification: Notification) => any;
enterTimeout?: number;
leaveTimeout?: number;
}
interface NotificationContainerProps {
enterTimeout?: number;
leaveTimeout?: number;
}
interface INotificationManagerCreate {
type: EventType,
title?: NotificationProps['title']
message?: NotificationProps['message']
timeout?: number,
onClick?: () => any,
priority?: boolean
}
class Notification extends React.Component<NotificationProps> {}
class NotificationContainer extends React.Component<NotificationContainerProps> {}
class NotificationManager extends EventEmitter {
static create(INotificationManagerCreate) : void
static info(message?: INotificationManagerCreate['message'], title?: INotificationManagerCreate['title'], timeOut?: INotificationManagerCreate['timeout'], onClick?: INotificationManagerCreate['onClick'], priority?: INotificationManagerCreate['priority']) : void
static success(message?: INotificationManagerCreate['message'], title?: INotificationManagerCreate['title'], timeOut?: INotificationManagerCreate['timeout'], onClick?: INotificationManagerCreate['onClick'], priority?: INotificationManagerCreate['priority']) : void
static warning(message?: INotificationManagerCreate['message'], title?: INotificationManagerCreate['title'], timeOut?: INotificationManagerCreate['timeout'], onClick?: INotificationManagerCreate['onClick'], priority?: INotificationManagerCreate['priority']) : void
static error(message?: INotificationManagerCreate['message'], title?: INotificationManagerCreate['title'], timeOut?: INotificationManagerCreate['timeout'], onClick?: INotificationManagerCreate['onClick'], priority?: INotificationManagerCreate['priority']) : void
static remove(notification: Notification) : void
}
} |
Any plans for this? Typings would be much appreciated
The text was updated successfully, but these errors were encountered: