Add types for ensure-error

This commit is contained in:
Dimitri Benin
2018-12-13 23:51:31 +01:00
parent 081247e44e
commit 85a4769fc7
4 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import ensureError = require('ensure-error');
const error = new TypeError('🦄');
// $ExpectType TypeError
ensureError(error);
// $ExpectType NonError
ensureError(10);

15
types/ensure-error/index.d.ts vendored Normal file
View File

@@ -0,0 +1,15 @@
// Type definitions for ensure-error 1.0
// Project: https://github.com/sindresorhus/ensure-error#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
export = ensureError;
declare function ensureError<T>(input: T): T extends Error ? T : ensureError.NonError;
declare namespace ensureError {
interface NonError extends Error {
name: 'NonError';
}
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ensure-error-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }