mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[whoops] Add types for whoops (#47000)
This commit is contained in:
parent
e0730a56e1
commit
2f615010a5
26
types/whoops/index.d.ts
vendored
Normal file
26
types/whoops/index.d.ts
vendored
Normal 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;
|
||||
23
types/whoops/tsconfig.json
Normal file
23
types/whoops/tsconfig.json
Normal 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
1
types/whoops/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
20
types/whoops/whoops-tests.ts
Normal file
20
types/whoops/whoops-tests.ts
Normal 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' });
|
||||
Loading…
Reference in New Issue
Block a user