From 3d017d28ed5b36f02b3026cd1a8ed0e8511ad2f4 Mon Sep 17 00:00:00 2001 From: Robin Labat Date: Mon, 24 Sep 2018 16:30:19 +0200 Subject: [PATCH] add standard-http-error typings --- types/standard-http-error/index.d.ts | 26 +++++++++++++++++++ .../standard-http-error-tests.ts | 16 ++++++++++++ types/standard-http-error/tsconfig.json | 16 ++++++++++++ types/standard-http-error/tslint.json | 1 + 4 files changed, 59 insertions(+) create mode 100644 types/standard-http-error/index.d.ts create mode 100644 types/standard-http-error/standard-http-error-tests.ts create mode 100644 types/standard-http-error/tsconfig.json create mode 100644 types/standard-http-error/tslint.json diff --git a/types/standard-http-error/index.d.ts b/types/standard-http-error/index.d.ts new file mode 100644 index 0000000000..14f72ea9a8 --- /dev/null +++ b/types/standard-http-error/index.d.ts @@ -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 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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; +} \ No newline at end of file diff --git a/types/standard-http-error/standard-http-error-tests.ts b/types/standard-http-error/standard-http-error-tests.ts new file mode 100644 index 0000000000..872bc3410d --- /dev/null +++ b/types/standard-http-error/standard-http-error-tests.ts @@ -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 \ No newline at end of file diff --git a/types/standard-http-error/tsconfig.json b/types/standard-http-error/tsconfig.json new file mode 100644 index 0000000000..cc399408e1 --- /dev/null +++ b/types/standard-http-error/tsconfig.json @@ -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"] +} diff --git a/types/standard-http-error/tslint.json b/types/standard-http-error/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/standard-http-error/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }