mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
TS 5.0's type guards return literal types in more cases than before, which changes the behaviour of many assert functions.
72 lines
1.2 KiB
TypeScript
72 lines
1.2 KiB
TypeScript
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
|
|
}
|
|
|
|
{
|
|
const a = 13 as number | null | undefined;
|
|
assert(a);
|
|
a; // $ExpectType number
|
|
}
|
|
|
|
{
|
|
const a = true as boolean;
|
|
assert.ok(a);
|
|
a; // $ExpectType true
|
|
}
|
|
|
|
{
|
|
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 || "test"
|
|
}
|
|
|
|
{
|
|
const a = 'test' as any;
|
|
assert.strict.equal(a, 'test');
|
|
a; // $ExpectType string || "test"
|
|
}
|
|
|
|
{
|
|
const a = { b: 2 } as any;
|
|
assert.deepStrictEqual(a, { b: 2 });
|
|
a; // $ExpectType { b: number; }
|
|
}
|
|
|
|
{
|
|
const a = { b: 2 } as any;
|
|
assert.strict.deepEqual(a, { b: 2 });
|
|
a; // $ExpectType { b: number; }
|
|
}
|
|
|
|
assert.fail(); // $ExpectType never
|