Merge pull request #3341 from github/robertbrignull/unknown_type_checking
Use unknown instead of any in type functions
This commit is contained in:
@@ -84,12 +84,13 @@ export interface ErrorLike {
|
|||||||
stack?: string;
|
stack?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isErrorLike(error: any): error is ErrorLike {
|
function isErrorLike(error: unknown): error is ErrorLike {
|
||||||
if (
|
return (
|
||||||
|
error !== undefined &&
|
||||||
|
error !== null &&
|
||||||
|
typeof error === "object" &&
|
||||||
|
"message" in error &&
|
||||||
typeof error.message === "string" &&
|
typeof error.message === "string" &&
|
||||||
(error.stack === undefined || typeof error.stack === "string")
|
(!("stack" in error) || typeof error.stack === "string")
|
||||||
) {
|
);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,8 +124,14 @@ export interface IOError {
|
|||||||
readonly code: string;
|
readonly code: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isIOError(e: any): e is IOError {
|
export function isIOError(e: unknown): e is IOError {
|
||||||
return e.code !== undefined && typeof e.code === "string";
|
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.
|
// This function is a wrapper around `os.tmpdir()` to make it easier to mock in tests.
|
||||||
|
|||||||
@@ -600,6 +600,11 @@ export class LocalQueries extends DisposableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isTabInputText(input: any): input is TabInputText {
|
function isTabInputText(input: unknown): input is TabInputText {
|
||||||
return input?.uri !== undefined;
|
return (
|
||||||
|
input !== null &&
|
||||||
|
typeof input === "object" &&
|
||||||
|
"uri" in input &&
|
||||||
|
input?.uri !== undefined
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user