mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Merge pull request #28571 from danwbyrne/mali-compose
adds typings for the 'mali-compose' package
This commit is contained in:
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// Type definitions for mali 1.1
|
||||
// Project: https://github.com/malijs/mali-compose
|
||||
// Definitions by: Daniel Byrne <https://github.com/danwbyrne>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
import { Context } from "mali";
|
||||
|
||||
declare function compose(
|
||||
middleware: ReadonlyArray<
|
||||
(ctx: Context, next: () => Promise<void>) => Promise<void>
|
||||
>
|
||||
): (context: Context, next: () => Promise<void>) => Promise<void>;
|
||||
|
||||
export = compose;
|
||||
@@ -0,0 +1,39 @@
|
||||
import compose = require('mali-compose');
|
||||
import { Context } from 'mali';
|
||||
|
||||
type middleware = (context: Context, next: () => Promise<void>) => Promise<void>;
|
||||
|
||||
const arr: number[] = [];
|
||||
const stack: middleware[] = [];
|
||||
|
||||
function _sleep(ms: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
stack.push(async (ctx: Context, next: () => Promise<void>) => {
|
||||
arr.push(1);
|
||||
await _sleep(1);
|
||||
await next();
|
||||
await _sleep(1);
|
||||
arr.push(6);
|
||||
});
|
||||
|
||||
stack.push(async (ctx: Context, next: () => Promise<void>) => {
|
||||
arr.push(2);
|
||||
await _sleep(1);
|
||||
await next();
|
||||
await _sleep(1);
|
||||
arr.push(5);
|
||||
});
|
||||
|
||||
stack.push(async (ctx: Context, next: () => Promise<void>) => {
|
||||
arr.push(3);
|
||||
await _sleep(1);
|
||||
await next();
|
||||
await _sleep(1);
|
||||
arr.push(4);
|
||||
});
|
||||
|
||||
compose(stack);
|
||||
compose([]);
|
||||
compose([compose(stack)]);
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"mali-compose-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user