directInstanceOf: Fix handling of undefined and null

Fixes #199
This commit is contained in:
Sindre Sorhus 2023-10-15 16:01:29 +07:00
parent 9d6c91ee58
commit e7e2213e91
2 changed files with 7 additions and 0 deletions

View file

@ -413,6 +413,10 @@ export function isDate(value: unknown): value is Date {
}
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;
}