diff --git a/types/assert/assert-tests.ts b/types/assert/assert-tests.ts index 3f795f0552..a2ebffefea 100644 --- a/types/assert/assert-tests.ts +++ b/types/assert/assert-tests.ts @@ -2,10 +2,14 @@ import * as assert from 'assert'; assert(true, "it's working"); -assert.ok(true, "inner functions work as well"); +assert.ok(true, 'inner functions work as well'); assert.throws(() => {}); assert.throws(() => {}, /Regex test/); -assert.throws(() => {}, () => {}, "works wonderfully"); +assert.throws( + () => {}, + () => {}, + 'works wonderfully', +); -assert['fail'](true, true, "works like a charm"); +assert['fail'](true, true, 'works like a charm'); diff --git a/types/assert/index.d.ts b/types/assert/index.d.ts index f436b7b4fd..9ae05ce63f 100644 --- a/types/assert/index.d.ts +++ b/types/assert/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/browserify/commonjs-assert, https://github.com/defunctzombie/commonjs-assert // Definitions by: Nico Gallinal // Linus Unnebäck +// ExE Boss // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare function assert(value: any, message?: string): void; @@ -29,7 +30,11 @@ declare namespace assert { 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 doesNotThrow( + block: () => void, + error: (() => void) | ((err: any) => boolean) | RegExp, + message?: string, + ): void; function ifError(value: any): void; @@ -41,7 +46,13 @@ declare namespace assert { operator: string; generatedMessage: boolean; - constructor(options?: { message?: string; actual?: any; expected?: any; operator?: string; stackStartFunction?: () => void }); + constructor(options?: { + message?: string; + actual?: any; + expected?: any; + operator?: string; + stackStartFunction?: () => void; + }); } } diff --git a/types/assert/package.json b/types/assert/package.json new file mode 100644 index 0000000000..f28600648d --- /dev/null +++ b/types/assert/package.json @@ -0,0 +1,7 @@ +{ + "private": true, + "types": "index", + "typesVersions": { + ">=3.7.0-0": { "*": ["ts3.7/*"] } + } +} diff --git a/types/assert/ts3.7/assert-tests.ts b/types/assert/ts3.7/assert-tests.ts new file mode 100644 index 0000000000..983748c1fd --- /dev/null +++ b/types/assert/ts3.7/assert-tests.ts @@ -0,0 +1,59 @@ +import * as assert from 'assert'; + +assert(true, "it's working"); + +assert.ok(true, 'inner functions work as well'); + +assert.throws(() => {}); +assert.throws(() => {}, /Regex test/); +assert.throws( + () => {}, + () => {}, + 'works wonderfully', +); + +assert['fail'](true, true, 'works like a charm'); + +{ + const a = null as any; + assert.ifError(a); + a; // $ExpectType null | undefined +} + +{ + const a = true as boolean; + assert(a); + a; // $ExpectType true +} + +{ + // tslint:disable-next-line: no-null-undefined-union + const a = 13 as number | null | undefined; + assert(a); + a; // $ExpectType number +} + +{ + const a = true as boolean; + assert.ok(a); + a; // $ExpectType true +} + +{ + // tslint:disable-next-line: no-null-undefined-union + const a = 13 as number | null | undefined; + assert.ok(a); + a; // $ExpectType number +} + +{ + const a = 'test' as any; + assert.strictEqual(a, 'test'); + a; // $ExpectType string +} + +{ + const a = { b: 2 } as any; + assert.deepStrictEqual(a, { b: 2 }); + a; // $ExpectType { b: number; } +} diff --git a/types/assert/ts3.7/index.d.ts b/types/assert/ts3.7/index.d.ts new file mode 100644 index 0000000000..2e62d81566 --- /dev/null +++ b/types/assert/ts3.7/index.d.ts @@ -0,0 +1,58 @@ +declare function assert(value: any, message?: string): asserts value; + +declare namespace assert { + function fail(actual?: any, expected?: any, message?: string, operator?: string): void; + + function ok(value: any, message?: string): asserts value; + + /** @deprecated Use `strictEqual` instead */ + function equal(actual: any, expected: any, message?: string): void; + + /** @deprecated Use `notStrictEqual` instead */ + function notEqual(actual: any, expected: any, message?: string): void; + + /** @deprecated Use `deepStrictEqual` instead */ + function deepEqual(actual: any, expected: any, message?: string): void; + + /** @deprecated Use `notDeepStrictEqual` instead */ + function notDeepEqual(actual: any, expected: any, message?: string): void; + + function deepStrictEqual(actual: any, expected: T, message?: string): asserts actual is T; + + function notDeepStrictEqual(actual: any, expected: any, message?: string): void; + + function strictEqual(actual: any, expected: T, message?: string): asserts actual is T; + + 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): asserts value is null | undefined; + + 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/ts3.7/tsconfig.json b/types/assert/ts3.7/tsconfig.json new file mode 100644 index 0000000000..98c4f2a3e2 --- /dev/null +++ b/types/assert/ts3.7/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es2015"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": ["../../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "assert-tests.ts", + "index.d.ts" + ] +} diff --git a/types/assert/ts3.7/tslint.json b/types/assert/ts3.7/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/assert/ts3.7/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/assert/tsconfig.json b/types/assert/tsconfig.json index 5ab217b2ab..e2f4f88baa 100644 --- a/types/assert/tsconfig.json +++ b/types/assert/tsconfig.json @@ -1,24 +1,19 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ - "es6", - "dom" - ], + "lib": ["es2015"], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", - "typeRoots": [ - "../" - ], + "typeRoots": ["../"], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts", - "assert-tests.ts" + "assert-tests.ts", + "index.d.ts" ] } diff --git a/types/assert/tslint.json b/types/assert/tslint.json index f93cf8562a..3db14f85ea 100644 --- a/types/assert/tslint.json +++ b/types/assert/tslint.json @@ -1,3 +1 @@ -{ - "extends": "dtslint/dt.json" -} +{ "extends": "dtslint/dt.json" }