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;
|
||||
}
|
||||
|
||||
function isErrorLike(error: any): error is ErrorLike {
|
||||
if (
|
||||
function isErrorLike(error: unknown): error is ErrorLike {
|
||||
return (
|
||||
error !== undefined &&
|
||||
error !== null &&
|
||||
typeof error === "object" &&
|
||||
"message" in error &&
|
||||
typeof error.message === "string" &&
|
||||
(error.stack === undefined || typeof error.stack === "string")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
(!("stack" in error) || typeof error.stack === "string")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -600,6 +600,11 @@ export class LocalQueries extends DisposableObject {
|
||||
}
|
||||
}
|
||||
|
||||
function isTabInputText(input: any): input is TabInputText {
|
||||
return input?.uri !== undefined;
|
||||
function isTabInputText(input: unknown): input is TabInputText {
|
||||
return (
|
||||
input !== null &&
|
||||
typeof input === "object" &&
|
||||
"uri" in input &&
|
||||
input?.uri !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user