It appears that there is already an existing GitHub issue related to this topic. You can find it here: ts#1213.
This type of usage resembles a high-order function, and I am unsure if TypeScript supports it.
Although the interface remains the same, there is a need to create both synchronous and asynchronous versions.
interface IO<T> {
get: () => T<number>;
set: (v: number) => T<boolean>;
}
type Raw<T> = T;
class SyncO implements IO<Raw> {
get() {
return 1;
}
set(v) {
v;
return true;
}
}
class AsyncO implements IO<Promise> {
get() {
return Promise.resolve(1);
}
set(v) {
v;
return Promise.resolve(true);
}
}