From 369b95cd669820a5d0e979a60fc4d7da8fe35f3c Mon Sep 17 00:00:00 2001 From: Robin Labat Date: Mon, 24 Sep 2018 16:16:42 +0200 Subject: [PATCH 1/4] add standard-error typings --- types/standard-error/index.d.ts | 21 +++++++++++++++++++ types/standard-error/standard-error-tests.ts | 13 ++++++++++++ types/standard-error/tsconfig.json | 22 ++++++++++++++++++++ types/standard-error/tslint.json | 1 + 4 files changed, 57 insertions(+) create mode 100644 types/standard-error/index.d.ts create mode 100644 types/standard-error/standard-error-tests.ts create mode 100644 types/standard-error/tsconfig.json create mode 100644 types/standard-error/tslint.json diff --git a/types/standard-error/index.d.ts b/types/standard-error/index.d.ts new file mode 100644 index 0000000000..c729b5ce66 --- /dev/null +++ b/types/standard-error/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for standard-error 1.1 +// Project: https://github.com/moll/js-standard-error +// Definitions by: Labat Robin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'standard-error' { + const StandardError: StandardError.constructor; + + namespace StandardError { + interface constructor { + new (message: string, props?: object): error; + new (props: object): error; + } + + interface error extends Error { + [key: string]: any; + } + } + + export = StandardError; +} \ No newline at end of file diff --git a/types/standard-error/standard-error-tests.ts b/types/standard-error/standard-error-tests.ts new file mode 100644 index 0000000000..9f17c4fc96 --- /dev/null +++ b/types/standard-error/standard-error-tests.ts @@ -0,0 +1,13 @@ +import * as StandardError from 'standard-error'; + +let error = new StandardError('test'); //$ExpectType StandardError.error + +error.message; //$ExpectType string +error.name; //$ExpectType string +error.stack; //$ExpectType string + +error = new StandardError({ name: 'test', foo: 'bar' }); //$ExpectType StandardError.error + +error.foo; //$ExpectType any + +error = new StandardError('test', { foo: 'bar' }); //$ExpectType StandardError.error \ No newline at end of file diff --git a/types/standard-error/tsconfig.json b/types/standard-error/tsconfig.json new file mode 100644 index 0000000000..b0be0191af --- /dev/null +++ b/types/standard-error/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "standard-error-tests.ts" + ] +} diff --git a/types/standard-error/tslint.json b/types/standard-error/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/standard-error/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 71c7f42382f1d48f7fe84ad066671cef9e267478 Mon Sep 17 00:00:00 2001 From: Robin Labat Date: Mon, 24 Sep 2018 16:30:11 +0200 Subject: [PATCH 2/4] add standard-error typings --- types/standard-error/index.d.ts | 21 ++++++++++++++++++++ types/standard-error/standard-error-tests.ts | 13 ++++++++++++ types/standard-error/tsconfig.json | 16 +++++++++++++++ types/standard-error/tslint.json | 1 + 4 files changed, 51 insertions(+) create mode 100644 types/standard-error/index.d.ts create mode 100644 types/standard-error/standard-error-tests.ts create mode 100644 types/standard-error/tsconfig.json create mode 100644 types/standard-error/tslint.json diff --git a/types/standard-error/index.d.ts b/types/standard-error/index.d.ts new file mode 100644 index 0000000000..c729b5ce66 --- /dev/null +++ b/types/standard-error/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for standard-error 1.1 +// Project: https://github.com/moll/js-standard-error +// Definitions by: Labat Robin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'standard-error' { + const StandardError: StandardError.constructor; + + namespace StandardError { + interface constructor { + new (message: string, props?: object): error; + new (props: object): error; + } + + interface error extends Error { + [key: string]: any; + } + } + + export = StandardError; +} \ No newline at end of file diff --git a/types/standard-error/standard-error-tests.ts b/types/standard-error/standard-error-tests.ts new file mode 100644 index 0000000000..9f17c4fc96 --- /dev/null +++ b/types/standard-error/standard-error-tests.ts @@ -0,0 +1,13 @@ +import * as StandardError from 'standard-error'; + +let error = new StandardError('test'); //$ExpectType StandardError.error + +error.message; //$ExpectType string +error.name; //$ExpectType string +error.stack; //$ExpectType string + +error = new StandardError({ name: 'test', foo: 'bar' }); //$ExpectType StandardError.error + +error.foo; //$ExpectType any + +error = new StandardError('test', { foo: 'bar' }); //$ExpectType StandardError.error \ No newline at end of file diff --git a/types/standard-error/tsconfig.json b/types/standard-error/tsconfig.json new file mode 100644 index 0000000000..b0e6e23d4b --- /dev/null +++ b/types/standard-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-error-tests.ts"] +} diff --git a/types/standard-error/tslint.json b/types/standard-error/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/standard-error/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From 3d017d28ed5b36f02b3026cd1a8ed0e8511ad2f4 Mon Sep 17 00:00:00 2001 From: Robin Labat Date: Mon, 24 Sep 2018 16:30:19 +0200 Subject: [PATCH 3/4] 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" } From d12ded0d4a19cfa36a851966611979091e9be95f Mon Sep 17 00:00:00 2001 From: Robin Labat Date: Mon, 24 Sep 2018 17:48:52 +0200 Subject: [PATCH 4/4] fix tests --- types/standard-error/index.d.ts | 20 ++++++--------- types/standard-error/standard-error-tests.ts | 16 ++++++------ types/standard-http-error/index.d.ts | 25 ++++++------------- .../standard-http-error-tests.ts | 22 ++++++++-------- 4 files changed, 34 insertions(+), 49 deletions(-) diff --git a/types/standard-error/index.d.ts b/types/standard-error/index.d.ts index c729b5ce66..4bdf04c33e 100644 --- a/types/standard-error/index.d.ts +++ b/types/standard-error/index.d.ts @@ -3,19 +3,13 @@ // Definitions by: Labat Robin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module 'standard-error' { - const StandardError: StandardError.constructor; +// TypeScript Version: 2.2 - namespace StandardError { - interface constructor { - new (message: string, props?: object): error; - new (props: object): error; - } +export = StandardError; - interface error extends Error { - [key: string]: any; - } - } +declare class StandardError extends Error { + [key: string]: any; - export = StandardError; -} \ No newline at end of file + constructor(message: string, props?: any); + constructor(props: any); +} diff --git a/types/standard-error/standard-error-tests.ts b/types/standard-error/standard-error-tests.ts index 9f17c4fc96..a5184da531 100644 --- a/types/standard-error/standard-error-tests.ts +++ b/types/standard-error/standard-error-tests.ts @@ -1,13 +1,13 @@ -import * as StandardError from 'standard-error'; +import StandardError = require('standard-error'); -let error = new StandardError('test'); //$ExpectType StandardError.error +let error = new StandardError('test'); // $ExpectType StandardError -error.message; //$ExpectType string -error.name; //$ExpectType string -error.stack; //$ExpectType string +error.message; // $ExpectType string +error.name; // $ExpectType string +error.stack; // $ExpectType string | undefined -error = new StandardError({ name: 'test', foo: 'bar' }); //$ExpectType StandardError.error +error = new StandardError({ name: 'test', foo: 'bar' }); // $ExpectType StandardError -error.foo; //$ExpectType any +error.foo; // $ExpectType any -error = new StandardError('test', { foo: 'bar' }); //$ExpectType StandardError.error \ No newline at end of file +error = new StandardError('test', { foo: 'bar' }); // $ExpectType StandardError diff --git a/types/standard-http-error/index.d.ts b/types/standard-http-error/index.d.ts index 14f72ea9a8..9b95acebeb 100644 --- a/types/standard-http-error/index.d.ts +++ b/types/standard-http-error/index.d.ts @@ -3,24 +3,15 @@ // Definitions by: Labat Robin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// +// TypeScript Version: 2.2 -declare module 'standard-http-error' { - import * as StandardError from 'standard-error'; +import StandardError = require('standard-error'); - const HttpError: HttpError.constructor; +export = HttpError; - namespace HttpError { - interface constructor { - new (code: number | string, message?: string, props?: object): error; - new (code: number | string, props?: object): error; - [key: string]: number | undefined; - } +declare class HttpError extends StandardError { + code: number; - interface error extends StandardError.error { - code: number; - } - } - - export = HttpError; -} \ No newline at end of file + constructor(code: number | string, message?: string, props?: object); + constructor(code: number | string, props?: object); +} diff --git a/types/standard-http-error/standard-http-error-tests.ts b/types/standard-http-error/standard-http-error-tests.ts index 872bc3410d..0b430774d2 100644 --- a/types/standard-http-error/standard-http-error-tests.ts +++ b/types/standard-http-error/standard-http-error-tests.ts @@ -1,16 +1,16 @@ -import * as HttpError from 'standard-http-error'; +import HttpError = require('standard-http-error'); -let error = new HttpError(200); //$ExpectType HttpError.error +let error = new HttpError(200); // $ExpectType HttpError -error.code; //$ExpectType number -error.message; //$ExpectType string -error.name; //$ExpectType string -error.stack; //$ExpectType string +error.code; // $ExpectType number +error.message; // $ExpectType string +error.name; // $ExpectType string +error.stack; // $ExpectType string | undefined -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 = new HttpError(200, 'test'); // $ExpectType HttpError +error = new HttpError('OK', 'test'); // $ExpectType HttpError +error = new HttpError(200, 'test', { foo: 'bar' }); // $ExpectType HttpError -error.foo; //$ExpectType any +error.foo; // $ExpectType any -error = new HttpError(200, { message: 'test', foo: 'bar' }); //$ExpectType HttpError.error \ No newline at end of file +error = new HttpError(200, { message: 'test', foo: 'bar' }); // $ExpectType HttpError