parent
9d6c91ee58
commit
e7e2213e91
2 changed files with 7 additions and 0 deletions
|
|
@ -413,6 +413,10 @@ export function isDate(value: unknown): value is Date {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDirectInstanceOf<T>(instance: unknown, class_: Class<T>): instance is T {
|
export function isDirectInstanceOf<T>(instance: unknown, class_: Class<T>): instance is T {
|
||||||
|
if (instance === undefined || instance === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return Object.getPrototypeOf(instance) === class_.prototype;
|
return Object.getPrototypeOf(instance) === class_.prototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -986,6 +986,9 @@ test('is.directInstanceOf', t => {
|
||||||
t.throws(() => {
|
t.throws(() => {
|
||||||
assert.directInstanceOf(errorSubclass, Error);
|
assert.directInstanceOf(errorSubclass, Error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
t.false(is.directInstanceOf(undefined, Error));
|
||||||
|
t.false(is.directInstanceOf(null, Error));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('is.urlInstance', t => {
|
test('is.urlInstance', t => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue