mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-01-30 21:47:35 +00:00
feat(assert): Add support for TypeScript 3.7 assertion functions (#41927)
Co-Authored-By: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se>
This commit is contained in:
parent
7c12944ed1
commit
00a3593da3
@ -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');
|
||||
|
||||
15
types/assert/index.d.ts
vendored
15
types/assert/index.d.ts
vendored
@ -2,6 +2,7 @@
|
||||
// Project: https://github.com/browserify/commonjs-assert, https://github.com/defunctzombie/commonjs-assert
|
||||
// Definitions by: Nico Gallinal <https://github.com/nicoabie>
|
||||
// Linus Unnebäck <https://github.com/LinusU>
|
||||
// ExE Boss <https://github.com/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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
7
types/assert/package.json
Normal file
7
types/assert/package.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"types": "index",
|
||||
"typesVersions": {
|
||||
">=3.7.0-0": { "*": ["ts3.7/*"] }
|
||||
}
|
||||
}
|
||||
59
types/assert/ts3.7/assert-tests.ts
Normal file
59
types/assert/ts3.7/assert-tests.ts
Normal file
@ -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; }
|
||||
}
|
||||
58
types/assert/ts3.7/index.d.ts
vendored
Normal file
58
types/assert/ts3.7/index.d.ts
vendored
Normal file
@ -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<T>(actual: any, expected: T, message?: string): asserts actual is T;
|
||||
|
||||
function notDeepStrictEqual(actual: any, expected: any, message?: string): void;
|
||||
|
||||
function strictEqual<T>(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;
|
||||
19
types/assert/ts3.7/tsconfig.json
Normal file
19
types/assert/ts3.7/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
1
types/assert/ts3.7/tslint.json
Normal file
1
types/assert/ts3.7/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.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"
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,3 +1 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user