mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-03-13 10:02:52 +00:00
Merge pull request #25925 from segayuu/create-types-iferr
Create @types/iferr
This commit is contained in:
commit
08e6ec3c77
38
types/iferr/iferr-tests.ts
Normal file
38
types/iferr/iferr-tests.ts
Normal file
@ -0,0 +1,38 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as fs from "fs";
|
||||
import iferr = require("iferr");
|
||||
|
||||
const { tiferr, throwerr, printerr } = iferr;
|
||||
|
||||
const { readFile } = fs;
|
||||
|
||||
const errcb = (err: Error | undefined) => { throw err; };
|
||||
|
||||
readFile("test.txt", iferr(errcb, result => {
|
||||
Buffer.from("test", "utf8") === result;
|
||||
}));
|
||||
|
||||
readFile("test.txt", "utf8", iferr(errcb, result => {
|
||||
"test" === result;
|
||||
}));
|
||||
|
||||
readFile("test.txt", tiferr(errcb, result => {
|
||||
Buffer.from("test", "utf8") === result;
|
||||
}));
|
||||
|
||||
readFile("test.txt", "utf8", tiferr(errcb, result => {
|
||||
"test" === result;
|
||||
}));
|
||||
|
||||
readFile("test.txt", throwerr(result => {
|
||||
Buffer.from("test", "utf8") === result;
|
||||
}));
|
||||
|
||||
readFile("test.txt", "utf8", throwerr(result => {
|
||||
"test" === result;
|
||||
}));
|
||||
|
||||
readFile("test.txt", printerr);
|
||||
|
||||
readFile("test.txt", "utf8", printerr);
|
||||
29
types/iferr/index.d.ts
vendored
Normal file
29
types/iferr/index.d.ts
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// Type definitions for iferr 1.0
|
||||
// Project: https://github.com/shesek/iferr
|
||||
// Definitions by: segayuu <https://github.com/segayuu>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
type nodeCallback<T> = (err: Error | undefined, ...a: T[]) => any;
|
||||
|
||||
// Delegates to `succ` on sucecss or to `fail` on error
|
||||
// ex: Thing.load(123, iferr(cb, thing => ...))
|
||||
declare function iferr<T>(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback<T>;
|
||||
|
||||
declare namespace iferr {
|
||||
// Delegates to `succ` on sucecss or to `fail` on error
|
||||
// ex: Thing.load(123, iferr(cb, thing => ...))
|
||||
function iferr<T>(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback<T>;
|
||||
|
||||
// Like iferr, but also catches errors thrown from `succ` and passes to `fail`
|
||||
function tiferr<T>(fail: (err: Error | undefined) => void, succ: (...result: T[]) => void): nodeCallback<T>;
|
||||
|
||||
// Delegate to the success function on success, throws the error otherwise
|
||||
// ex: Thing.load(123, throwerr(thing => ...))
|
||||
function throwerr<T>(succ: (...result: T[]) => void): nodeCallback<T>;
|
||||
|
||||
// Prints errors when one is passed, or does nothing otherwise
|
||||
// ex: Thing.load(123, printerr)
|
||||
function printerr(): nodeCallback<any>;
|
||||
}
|
||||
|
||||
export = iferr;
|
||||
23
types/iferr/tsconfig.json
Normal file
23
types/iferr/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"iferr-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/iferr/tslint.json
Normal file
1
types/iferr/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user