[英]React TypeScript with antd
這是我的代碼
import { notification } from "antd";
const openNotificationWithIcon = (type: string, message: string, err: string) => {
if(type == 'success' || type == 'warning')
notification[type] = ({ message: message, description: err}) *//error here*
return;
};
export default openNotificationWithIcon;
但它在消息中有錯誤
Type '{ message: string; description: string; }' is not assignable to type '((args: ArgsProps) => void) & ((args: ArgsProps) => void)'.
Object literal may only specify known properties, and 'message' does not exist in type '((args: ArgsProps) => void) & ((args: ArgsProps) => void)'
我在 antd 中看到該消息需要 ReactNode 類型,我修復了但它沒有發生
似乎是 notificitaion['success' | 'warning'] 是 function。這意味着您需要調用它而不是分配。
所以正確的使用方法是
import { notification } from "antd";
const openNotificationWithIcon = (type: string, message: string, err: string) => {
if(type == 'success' || type == 'warning')
notification[type]({ message: message, description: err});
return;
};
export default openNotificationWithIcon;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.