Skip to content

Commit f6301ab

Browse files
remove unsafe type predicate
1 parent 99e300f commit f6301ab

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/eslint-plugin/src/rules/unified-signatures.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,18 @@ export default createRule<Options, MessageIds>({
302302
: undefined;
303303
}
304304

305-
function isThisParam(
306-
param: TSESTree.Parameter | undefined,
307-
): param is TSESTree.Identifier {
308-
return param?.type === AST_NODE_TYPES.Identifier && param.name === 'this';
305+
function isThisParam(param: TSESTree.Parameter | undefined): boolean {
306+
return (
307+
param != null &&
308+
param.type === AST_NODE_TYPES.Identifier &&
309+
param.name === 'this'
310+
);
309311
}
310312

311313
function isThisVoidParam(param: TSESTree.Parameter | undefined) {
312314
return (
313315
isThisParam(param) &&
314-
param.typeAnnotation?.typeAnnotation.type ===
316+
(param as TSESTree.Identifier).typeAnnotation?.typeAnnotation.type ===
315317
AST_NODE_TYPES.TSVoidKeyword
316318
);
317319
}
@@ -332,8 +334,8 @@ export default createRule<Options, MessageIds>({
332334
const shorter = sig1.length < sig2.length ? sig1 : sig2;
333335
const shorterSig = sig1.length < sig2.length ? a : b;
334336

335-
const firstParam1 = sig1[0];
336-
const firstParam2 = sig2[0];
337+
const firstParam1 = sig1.at(0);
338+
const firstParam2 = sig2.at(0);
337339
// If one signature has explicit this type and another doesn't, they can't
338340
// be unified.
339341
if (isThisParam(firstParam1) !== isThisParam(firstParam2)) {

0 commit comments

Comments
 (0)