Convert isIOError to use unknown

This commit is contained in:
Robert
2024-02-06 17:25:24 +00:00
parent 3b366a6f51
commit 6e53f28972

View File

@@ -124,8 +124,14 @@ export interface IOError {
readonly code: string;
}
export function isIOError(e: any): e is IOError {
return e.code !== undefined && typeof e.code === "string";
export function isIOError(e: unknown): e is IOError {
return (
e !== undefined &&
e !== null &&
typeof e === "object" &&
"code" in e &&
typeof e.code === "string"
);
}
// This function is a wrapper around `os.tmpdir()` to make it easier to mock in tests.