[whoops] Add types for whoops (#47000)

This commit is contained in:
Florian Imdahl 2020-08-28 11:38:47 +02:00 committed by GitHub
parent e0730a56e1
commit 2f615010a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 0 deletions

26
types/whoops/index.d.ts vendored Normal file
View File

@ -0,0 +1,26 @@
// Type definitions for whoops 4.1
// Project: https://github.com/Kikobeats/whoops
// Definitions by: Florian Imdahl <https://github.com/ffflorian>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.9
declare namespace createErrorClass {
type ExtendError<E extends Error, P extends Record<string, any> = any> = (propsOrMessage?: P | string) => E & P;
function type(className?: string, props?: Record<string, any>): ExtendError<TypeError>;
function range(className?: string, props?: Record<string, any>): ExtendError<RangeError>;
// function eval(className?: string, props?: Record<string, any>): ExtendError<EvalError>;
function syntax(className?: string, props?: Record<string, any>): ExtendError<SyntaxError>;
function reference(className?: string, props?: Record<string, any>): ExtendError<ReferenceError>;
function uri(className?: string, props?: Record<string, any>): ExtendError<URIError>;
}
declare function createErrorClass(className?: string, props?: Record<string, any>): createErrorClass.ExtendError<Error>;
declare function createErrorClass(className?: 'TypeError', props?: Record<string, any>): createErrorClass.ExtendError<TypeError>;
declare function createErrorClass(className?: 'RangeError', props?: Record<string, any>): createErrorClass.ExtendError<RangeError>;
declare function createErrorClass(className?: 'EvalError', props?: Record<string, any>): createErrorClass.ExtendError<EvalError>;
declare function createErrorClass(className?: 'SyntaxError', props?: Record<string, any>): createErrorClass.ExtendError<SyntaxError>;
declare function createErrorClass(className?: 'ReferenceError', props?: Record<string, any>): createErrorClass.ExtendError<ReferenceError>;
declare function createErrorClass(className?: 'URIError', props?: Record<string, any>): createErrorClass.ExtendError<URIError>;
export = createErrorClass;

View 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",
"whoops-tests.ts"
]
}

1
types/whoops/tslint.json Normal file
View File

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

View File

@ -0,0 +1,20 @@
import whoops = require('whoops');
const simpleUserError = whoops('UserError');
throw simpleUserError('User not found');
const basicError = whoops();
throw basicError();
const userError2 = whoops('userError');
throw userError2();
const extendedError = whoops('userError', { code: 'ENOVALID' });
extendedError().code;
const extendedUserError = whoops('userError', {
code: 'ENOVALID',
message: (props: any) => `User '${props.username}' not found`,
});
extendedUserError({ username: 'kiko' });