Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
improve typings
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Sep 20, 2016
1 parent bb545b8 commit a7f5304
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 87 deletions.
45 changes: 18 additions & 27 deletions thunks.d.ts → index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* Type definitions for thunks
* https://github.com/thunks/thunks
* Definitions by: zensh <https://github.com/zensh>
*/
// Type definitions for thunks
// Project: https://github.com/thunks/thunks
// Definitions by: zensh <https://github.com/zensh>

// Import: `import * as thunks from 'thunks'`
// Import: `import { thunk, thunks, isGeneratorFn } from 'thunks'`

type primitives = boolean | number | string | Array<any> | Object | void;
type thunkable = ThunkLikeFunction | GeneratorFunction | AsyncFunction | PromiseLike | ToThunk | ToPromise | Generator;
type FunctionWithCallback = FnWithCb0 | FnWithCb1 | FnWithCb2 | FnWithCb3 | FnWithCb4 | FnWithCb5 | FnWithCb6 | FnWithCb7 | FnWithCb8;
type FunctionWithCallback = FnWithCb0 | FnWithCb1 | FnWithCb2 | FnWithCb3 | FnWithCb4 | FnWithCb5;
type ThunkOptions = ScopeOnerror | ScopeOptions | thunks.Scope

interface Callback {
(err?: Error, res?: primitives): primitives | thunkable;
Expand All @@ -20,37 +22,26 @@ interface ThunkFunction {
(fn?: Callback | GeneratorFunction | AsyncFunction): ThunkFunction;
}

// https://github.com/Microsoft/TypeScript/issues/1360
interface NodeCallback {
(err?: Error, ...args: Array<primitives>): void;
(err?: Error, ...args: Array<any>): void;
}

interface FnWithCb0 {
(callback: NodeCallback): void;
}
interface FnWithCb1 {
(arg1: primitives, callback: NodeCallback): void;
(arg1: any, callback: NodeCallback): void;
}
interface FnWithCb2 {
(arg1: primitives, arg2: primitives, callback: NodeCallback): void;
(arg1: any, arg2: any, callback: NodeCallback): void;
}
interface FnWithCb3 {
(arg1: primitives, arg2: primitives, arg3: primitives, callback: NodeCallback): void;
(arg1: any, arg2: any, arg3: any, callback: NodeCallback): void;
}
interface FnWithCb4 {
(arg1: primitives, arg2: primitives, arg3: primitives, arg4: primitives, callback: NodeCallback): void;
(arg1: any, arg2: any, arg3: any, arg4: any, callback: NodeCallback): void;
}
interface FnWithCb5 {
(arg1: primitives, arg2: primitives, arg3: primitives, arg4: primitives, arg5: primitives, callback: NodeCallback): void;
}
interface FnWithCb6 {
(arg1: primitives, arg2: primitives, arg3: primitives, arg4: primitives, arg5: primitives, arg6: primitives, callback: NodeCallback): void;
}
interface FnWithCb7 {
(arg1: primitives, arg2: primitives, arg3: primitives, arg4: primitives, arg5: primitives, arg6: primitives, arg7: primitives, callback: NodeCallback): void;
}
interface FnWithCb8 {
(arg1: primitives, arg2: primitives, arg3: primitives, arg4: primitives, arg5: primitives, arg6: primitives, arg7: primitives, arg8: primitives, callback: NodeCallback): void;
(arg1: any, arg2: any, arg3: any, arg4: any, arg5: any, callback: NodeCallback): void;
}

interface ToThunk {
Expand Down Expand Up @@ -131,18 +122,18 @@ interface Thunk {
cancel(): void;
}

declare function thunks (options?: ScopeOnerror | ScopeOptions): Thunk;
declare module thunks {
declare function thunks (options?: ThunkOptions): Thunk;
declare namespace thunks {
export const NAME: string;
export const VERSION: string;
export const pruneErrorStack: boolean;
export const thunk: Thunk;
export function thunks (options?: ScopeOnerror | ScopeOptions): Thunk;
export function thunks (options?: ThunkOptions): Thunk;
export function isGeneratorFn(fn: any): boolean;
export function isAsyncFn(fn: any): boolean;
export function isThunkableFn(fn: any): boolean;
export class Scope {
constructor(options?: ScopeOnerror | ScopeOptions);
constructor(options?: ThunkOptions);
}
}

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"authors": [
"Yan Qing <admin@zensh.com>"
],
"version": "4.7.3",
"version": "4.7.4",
"main": "thunks.js",
"typings": "thunks.d.ts",
"typings": "index.d.ts",
"jsnext:main": "thunks.es6.js",
"repository": {
"type": "git",
Expand Down Expand Up @@ -38,11 +38,11 @@
"promise": "^7.1.1",
"regenerator": "^0.8.46",
"should": "^11.1.0",
"standard": "^8.0.0",
"standard": "^8.1.0",
"thenjs": "^2.0.3",
"tman": "^1.4.5",
"tman": "^1.4.6",
"ts-node": "^1.3.0",
"typescript": "^2.0.2"
"typescript": "^1.8.10"
},
"scripts": {
"test": "standard && tman test/index",
Expand All @@ -52,8 +52,8 @@
},
"files": [
"README.md",
"index.d.ts",
"thunks.js",
"thunks.d.ts",
"thunks.es6.js"
]
}
7 changes: 0 additions & 7 deletions test.ts

This file was deleted.

0 comments on commit a7f5304

Please sign in to comment.