mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
feat: add posterus types (#42751)
This commit is contained in:
parent
904aad7a9e
commit
d09bdf8d8c
3
types/posterus/fiber.d.ts
vendored
Normal file
3
types/posterus/fiber.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { Future } from './index';
|
||||
|
||||
export function fiber(iterator: IterableIterator<any>): Future;
|
||||
40
types/posterus/index.d.ts
vendored
Normal file
40
types/posterus/index.d.ts
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// Type definitions for posterus 0.4
|
||||
// Project: https://github.com/Mitranim/posterus#readme
|
||||
// Definitions by: David Govea <https://github.com/DefinitelyTyped>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
export class Future<T = any, E extends Error = Error> {
|
||||
static from: <T = any, E extends Error = Error>(result?: T, error?: E) => Future<T, E>;
|
||||
static fromResult: <T = any>(...args: T extends undefined ? [] | [undefined] : [T]) => Future<T>;
|
||||
static fromError: <E extends Error = Error>(error: E) => Future<undefined, E>;
|
||||
static fromPromise: <T>(promise: Promise<T>) => Future<T>;
|
||||
static all: (values: any[]) => Future;
|
||||
static race: (values: any[]) => Future;
|
||||
static onUnhandledRejection: (future: Future) => void;
|
||||
static scheduler: Scheduler;
|
||||
|
||||
map: <U = any, V extends Error = Error>(
|
||||
mapper: (error?: E, result?: T) => U | Promise<U> | Future<U, V>,
|
||||
) => Future<U, V>;
|
||||
mapResult: <U = any, V extends Error = Error>(mapper: (result: T) => U | Promise<U> | Future<U, V>) => Future<U, V>;
|
||||
mapError: <U = any, V extends Error = Error>(mapper: (error: E) => U | Promise<U> | Future<U, V>) => Future<U, V>;
|
||||
finally: (mapper: (error?: E, result?: T) => any) => Future<T, E>;
|
||||
deinit: () => void;
|
||||
weak: () => Future<T, E>;
|
||||
settle: (error?: E, result?: T) => void;
|
||||
toPromise: () => Promise<T>;
|
||||
then: Promise<T>['then'];
|
||||
catch: Promise<T>['catch'];
|
||||
finishPending: () => void;
|
||||
deref: () => T | undefined;
|
||||
}
|
||||
|
||||
export class Scheduler {
|
||||
tick(): void;
|
||||
deinit(): void;
|
||||
asap(callback: () => void): void;
|
||||
}
|
||||
|
||||
export function isFuture(value: any): boolean;
|
||||
export function isDeinitError(error: any): boolean;
|
||||
30
types/posterus/posterus-tests.ts
Normal file
30
types/posterus/posterus-tests.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { Future, Scheduler } from 'posterus';
|
||||
import { fiber } from 'posterus/fiber';
|
||||
|
||||
const anyFuture = new Future();
|
||||
anyFuture.settle(undefined, 10);
|
||||
anyFuture.settle(undefined, 'foo');
|
||||
anyFuture.settle('not an Error'); // $ExpectError
|
||||
|
||||
const future = new Future<string>();
|
||||
future.settle(undefined, 'result');
|
||||
future.settle(undefined, 10); // $ExpectError
|
||||
|
||||
const undefinedResult = Future.fromResult();
|
||||
|
||||
const futureString = future.mapResult<string>(() => 'result');
|
||||
|
||||
const futureWrongType = future.mapResult<string>(() => 9000); // $ExpectError
|
||||
|
||||
function* generatorTask() {
|
||||
yield Promise.resolve();
|
||||
return Promise.resolve(10);
|
||||
}
|
||||
const task = fiber(generatorTask())
|
||||
.mapResult(res => 11)
|
||||
.finally(() => ({}));
|
||||
|
||||
Future.scheduler.asap(() => {});
|
||||
const scheduler = new Scheduler();
|
||||
scheduler.tick();
|
||||
scheduler.deinit();
|
||||
23
types/posterus/tsconfig.json
Normal file
23
types/posterus/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"posterus-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/posterus/tslint.json
Normal file
1
types/posterus/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user