javascript - Flow restrict to extend a class by assigment methods from callback
问题描述
StackOverflow community! The $Subtype<>
utility allows to do a lot of weird stuff flowtyping. Now I need to escape old functionality using the $Super utility and Generics. Literally flow spec is very brief, I couldn't find anything about how to extend an instance of a class with new methods. Please, help me to FlowFix .
I've tried a lot of tricks, but, look, I can't change a conduct aka usage of this function.
/* @flow */
class MainClass<C> {
constructor(
callback: (
resolve: (result?: any) => void,
reject: (error?: any) => void
) => mixed
): void {
// Contructor things
}
}
type ExtendedClass<D> = MainClass<D> & {
resolve(D): void;
reject(Error): void;
}
export function extended<D>(): ExtendedClass<D> {
let resolve;
let reject;
const main: MainClass<D> = new MainClass((res, rej) => {
resolve = res;
reject = rej;
});
main.resolve = resolve;
main.reject = reject;
return main;
}
main.resolve = resolve;
^ Cannot assign `resolve` to `main.resolve` because property `resolve` is missing in `MainClass` [1].
References:
22: const main: MainClass<D> = new MainClass((res, rej) => {
^ [1]
解决方案
推荐阅读
- spring-integration - Spring文件集成java配置
- arrays - 循环浏览所有网页的链接并再次导航
- r - 当 id 变量在列标题中编码时将数据从宽格式转换为长格式
- android - 回调侦听器未调用 Android ViewModel
- android - Android应用中WebView+webRTC中授予权限的问题
- javascript - 循环内递增或递减文本框值(非属性)
- php - laravel 更新后的碳错误尾随数据
- flutter - 需要将变量作为属性传递给可重用的小部件
- java - 使用哪些方法代替 if-else 语句?
- c++ - 根据 GL 标志的 Visual Studio 19-17 库兼容性