Skip to content

Commit b362620

Browse files
refactor(experimental-utils): simplify eslint-utils' predicate types in ast-utils even more (#3569)
1 parent 72d53e4 commit b362620

File tree

1 file changed

+15
-13
lines changed
  • packages/experimental-utils/src/ast-utils/eslint-utils

1 file changed

+15
-13
lines changed

packages/experimental-utils/src/ast-utils/eslint-utils/predicates.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import * as eslintUtils from 'eslint-utils';
22
import { TSESTree } from '../../ts-estree';
33

4-
type IsPunctuatorTokenWithValueFunction<Value extends string> = (
4+
type IsSpecificTokenFunction<SpecificToken extends TSESTree.Token> = (
55
token: TSESTree.Token,
6-
) => token is TSESTree.PunctuatorToken & { value: Value };
6+
) => token is SpecificToken;
77

8-
type IsNotPunctuatorTokenWithValueFunction<Value extends string> = (
8+
type IsNotSpecificTokenFunction<SpecificToken extends TSESTree.Token> = (
99
token: TSESTree.Token,
10-
) => token is Exclude<
11-
TSESTree.Token,
12-
TSESTree.PunctuatorToken & { value: Value }
13-
>;
10+
) => token is Exclude<TSESTree.Token, SpecificToken>;
11+
12+
type PunctuatorTokenWithValue<Value extends string> =
13+
TSESTree.PunctuatorToken & { value: Value };
14+
type IsPunctuatorTokenWithValueFunction<Value extends string> =
15+
IsSpecificTokenFunction<PunctuatorTokenWithValue<Value>>;
16+
type IsNotPunctuatorTokenWithValueFunction<Value extends string> =
17+
IsNotSpecificTokenFunction<PunctuatorTokenWithValue<Value>>;
1418

1519
const isArrowToken =
1620
eslintUtils.isArrowToken as IsPunctuatorTokenWithValueFunction<'=>'>;
@@ -42,12 +46,10 @@ const isCommaToken =
4246
const isNotCommaToken =
4347
eslintUtils.isNotCommaToken as IsNotPunctuatorTokenWithValueFunction<','>;
4448

45-
const isCommentToken = eslintUtils.isCommentToken as (
46-
token: TSESTree.Token,
47-
) => token is TSESTree.Comment;
48-
const isNotCommentToken = eslintUtils.isNotCommentToken as (
49-
token: TSESTree.Token,
50-
) => token is Exclude<TSESTree.Token, TSESTree.Comment>;
49+
const isCommentToken =
50+
eslintUtils.isCommentToken as IsSpecificTokenFunction<TSESTree.Comment>;
51+
const isNotCommentToken =
52+
eslintUtils.isNotCommentToken as IsNotSpecificTokenFunction<TSESTree.Comment>;
5153

5254
const isOpeningBraceToken =
5355
eslintUtils.isOpeningBraceToken as IsPunctuatorTokenWithValueFunction<'{'>;

0 commit comments

Comments
 (0)