48 lines
984 B
TypeScript
48 lines
984 B
TypeScript
import { makeFluent } from "../base";
|
|
import type { HKT } from "../base/hkt";
|
|
import {
|
|
Mixin,
|
|
type Input,
|
|
type Props,
|
|
type Return,
|
|
} from "../base/mixin";
|
|
import type { Empty } from "../internal";
|
|
import type { Methods } from "../registry";
|
|
import { Base } from "./base";
|
|
|
|
class Awaited<T extends Promise<unknown>> {
|
|
public value: T;
|
|
public constructor(value: T) {
|
|
this.value = value;
|
|
}
|
|
}
|
|
|
|
export interface AwaitedMixin extends Mixin.HKT {
|
|
new: (t: HKT.T<this>) => Input<typeof t> extends infer T
|
|
? T extends Promise<unknown>
|
|
? {
|
|
readonly awaited: Return<Awaited<T>, typeof t>;
|
|
}
|
|
: 0
|
|
: never;
|
|
}
|
|
|
|
export const AwaitedMixin = Mixin<AwaitedMixin>(
|
|
(value, $, fluent) => {},
|
|
);
|
|
|
|
if (import.meta.vitest) {
|
|
const { test, expect } = import.meta.vitest;
|
|
|
|
const registry = [Base, AwaitedMixin] as const;
|
|
const $ = makeFluent(registry);
|
|
|
|
test(".awaited", () => {
|
|
const promise = new Promise<number>((r) => {
|
|
r(10);
|
|
});
|
|
|
|
const m = $(promise).V;
|
|
});
|
|
}
|