如何解决打字稿解决皮棉功能
我用打字稿的 linter 返回了这个错误:
不要使用 Function
作为类型。 Function
类型接受任何类似函数的值。
它在调用函数时不提供类型安全,这可能是错误的常见来源。
它还接受类声明之类的内容,这些内容将在运行时抛出,因为它们不会被 new
调用。
如果您希望函数接受某些参数,则应明确定义函数 shape.eslint@typescript-eslint/ban-types)
我使用 quasar 的通知插件: https://next.quasar.dev/quasar-plugins/notify
我该如何解决这个错误?
这是我的代码
let masquerNotification:Function
function afficherNotification () {
if (notification.value && notification.value.message !== '') {
masquerNotification = $q.notify({
type: notification.value.type,message: notification.value.message,position: 'bottom-right',timeout: notification.value.timeout,actions: [{ icon: 'close',color: 'white' }]
})
void nettoyerNotification()
}
if (notification.value.masquer) {
masquerNotification()
}
}
!
解决方法
请使用 ()=>void 而不是函数类型。
let masquerNotification: () => void = () => {
if (notification.value && notification.value.message !== '') {
masquerNotification = $q.notify({
type: notification.value.type,message: notification.value.message,position: 'bottom-right',timeout: notification.value.timeout,actions: [{ icon: 'close',color: 'white' }],});
void nettoyerNotification();
}
if (notification.value.masquer) {
masquerNotification();
}
};
或
let masquerNotification: () => void = () => {
function afficherNotification(){
if (notification.value && notification.value.message !== '') {
masquerNotification = $q.notify({
type: notification.value.type,});
void nettoyerNotification();
}
if (notification.value.masquer) {
masquerNotification();
}
}
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。