add standard-http-error typings

This commit is contained in:
Robin Labat
2018-09-24 16:30:19 +02:00
parent 71c7f42382
commit 3d017d28ed
4 changed files with 59 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for standard-http-error 2.0
// Project: https://github.com/moll/js-standard-http-error
// Definitions by: Labat Robin <https://github.com/roblabat>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="standard-error" />
declare module 'standard-http-error' {
import * as StandardError from 'standard-error';
const HttpError: HttpError.constructor;
namespace HttpError {
interface constructor {
new (code: number | string, message?: string, props?: object): error;
new (code: number | string, props?: object): error;
[key: string]: number | undefined;
}
interface error extends StandardError.error {
code: number;
}
}
export = HttpError;
}
@@ -0,0 +1,16 @@
import * as HttpError from 'standard-http-error';
let error = new HttpError(200); //$ExpectType HttpError.error
error.code; //$ExpectType number
error.message; //$ExpectType string
error.name; //$ExpectType string
error.stack; //$ExpectType string
error = new HttpError(200, 'test'); //$ExpectType HttpError.error
error = new HttpError('OK', 'test'); //$ExpectType HttpError.error
error = new HttpError(200, 'test', { foo: 'bar' }); //$ExpectType HttpError.error
error.foo; //$ExpectType any
error = new HttpError(200, { message: 'test', foo: 'bar' }); //$ExpectType HttpError.error
+16
View File
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "standard-http-error-tests.ts"]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }