繁体   English   中英

反应 TypeScript 与 antd

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM