From 7aa33346269ead700535e5bcfb19a35a649f8b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Andr=C3=A9s=20Gallinal?= Date: Tue, 2 Oct 2018 15:37:55 -0300 Subject: [PATCH] Add types for browserify/commonjs-assert (#29188) * add types for browserify/commonjs-assert * fix tests and rename to 'assert' * fix some linting errors, checking in to avoid closing of pull request * fixed all lint errors --- types/assert/assert-tests.ts | 10 ++++++++ types/assert/index.d.ts | 45 ++++++++++++++++++++++++++++++++++++ types/assert/tsconfig.json | 24 +++++++++++++++++++ types/assert/tslint.json | 3 +++ 4 files changed, 82 insertions(+) create mode 100644 types/assert/assert-tests.ts create mode 100644 types/assert/index.d.ts create mode 100644 types/assert/tsconfig.json create mode 100644 types/assert/tslint.json diff --git a/types/assert/assert-tests.ts b/types/assert/assert-tests.ts new file mode 100644 index 0000000000..22248c18bd --- /dev/null +++ b/types/assert/assert-tests.ts @@ -0,0 +1,10 @@ +import * as assert from 'assert'; + +assert(true, "it's working"); + +assert.ok(true, "inner functions work as well"); + +assert.throws(() => {}); +assert.throws(() => {}, () => {}, "works wonderfully"); + +assert['fail'](true, true, "works like a charm"); diff --git a/types/assert/index.d.ts b/types/assert/index.d.ts new file mode 100644 index 0000000000..d79805f5af --- /dev/null +++ b/types/assert/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for commonjs-assert 1.4 +// Project: https://github.com/browserify/commonjs-assert +// Definitions by: Nico Gallinal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function assert(value: any, message?: string): void; + +declare namespace assert { + function fail(actual?: any, expected?: any, message?: string, operator?: string): void; + + function ok(value: any, message?: string): void; + + function equal(actual: any, expected: any, message?: string): void; + + function notEqual(actual: any, expected: any, message?: string): void; + + function deepEqual(actual: any, expected: any, message?: string): void; + + function notDeepEqual(acutal: any, expected: any, message?: string): void; + + function strictEqual(actual: any, expected: any, message?: string): void; + + function notStrictEqual(actual: any, expected: any, message?: string): void; + + function throws(block: () => void, message?: string): void; + function throws(block: () => void, error: () => void | ((err: any) => boolean) | RegExp, message?: string): void; + + function doesNotThrow(block: () => void, message?: string): void; + function doesNotThrow(block: () => void, error: () => void | ((err: any) => boolean) | RegExp, message?: string): void; + + function ifError(value: any): void; + + class AssertionError implements Error { + name: string; + message: string; + actual: any; + expected: any; + operator: string; + generatedMessage: boolean; + + constructor(options?: { message?: string; actual?: any; expected?: any; operator?: string; stackStartFunction?: () => void }); + } +} + +export = assert; diff --git a/types/assert/tsconfig.json b/types/assert/tsconfig.json new file mode 100644 index 0000000000..5ab217b2ab --- /dev/null +++ b/types/assert/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "assert-tests.ts" + ] +} diff --git a/types/assert/tslint.json b/types/assert/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/assert/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}