From 369b95cd669820a5d0e979a60fc4d7da8fe35f3c Mon Sep 17 00:00:00 2001 From: Robin Labat Date: Mon, 24 Sep 2018 16:16:42 +0200 Subject: [PATCH] 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" }