我希望有一个通用类型,而不是通用类型,也就是更高种类的类型:
abstract class MyClass<URI> { // URI can be Observable or Promise
// This obviously doesn't work, but that's the idea I have
abstract run(): URI<number> {
//... should return Promise<Number> or Observable<Number>, depending on URI
}
}
export interface HKT<URI, A> {
readonly _URI: URI;
readonly _A: A;
}
abstract class MyClass<URI> {
abstract run(): HKT<URI, number>;
}
我基本上只需要像这样对Observable和Promise进行模块扩充:
declare module "rxjs" {
interface Observable<T> {
_URI: "Observable";
_A: T;
}
}
但是,如何为Promise进行模块扩充?
// This doesn't work...
interface Promise<T> {
_URI: "Promise";
_A: T;
}
这是一个codeandbox链接:https://codesandbox.io/embed/billowing-darkness-89mry
答案 0 :(得分:0)
找到我的答案。
declare global {
interface Promise<T> {
_URI: 'Promise';
_A: T;
}
}