Skip to content

Commit 6472ea8

Browse files
Merge pull request #3341 from github/robertbrignull/unknown_type_checking
Use unknown instead of any in type functions
2 parents 5a80d02 + e943e7f commit 6472ea8

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

extensions/ql-vscode/src/common/errors.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ export interface ErrorLike {
8484
stack?: string;
8585
}
8686

87-
function isErrorLike(error: any): error is ErrorLike {
88-
if (
87+
function isErrorLike(error: unknown): error is ErrorLike {
88+
return (
89+
error !== undefined &&
90+
error !== null &&
91+
typeof error === "object" &&
92+
"message" in error &&
8993
typeof error.message === "string" &&
90-
(error.stack === undefined || typeof error.stack === "string")
91-
) {
92-
return true;
93-
}
94-
return false;
94+
(!("stack" in error) || typeof error.stack === "string")
95+
);
9596
}

extensions/ql-vscode/src/common/files.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,14 @@ export interface IOError {
124124
readonly code: string;
125125
}
126126

127-
export function isIOError(e: any): e is IOError {
128-
return e.code !== undefined && typeof e.code === "string";
127+
export function isIOError(e: unknown): e is IOError {
128+
return (
129+
e !== undefined &&
130+
e !== null &&
131+
typeof e === "object" &&
132+
"code" in e &&
133+
typeof e.code === "string"
134+
);
129135
}
130136

131137
// This function is a wrapper around `os.tmpdir()` to make it easier to mock in tests.

extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,11 @@ export class LocalQueries extends DisposableObject {
600600
}
601601
}
602602

603-
function isTabInputText(input: any): input is TabInputText {
604-
return input?.uri !== undefined;
603+
function isTabInputText(input: unknown): input is TabInputText {
604+
return (
605+
input !== null &&
606+
typeof input === "object" &&
607+
"uri" in input &&
608+
input?.uri !== undefined
609+
);
605610
}

0 commit comments

Comments
 (0)