Skip to content

Commit d0977d0

Browse files
armano2bradzacher
authored andcommitted
chore(types): improve typing for getTokenType and convertBodyEx… (typescript-eslint#1332)
* chore(types): improve typing for getTokenType and convertBodyExpressions * chore(types): remove unnecessary any cast and type * chore(types): restore original condition
1 parent 6b7b88b commit d0977d0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

packages/typescript-estree/src/convert.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export class Converter {
268268
private convertBodyExpressions(
269269
nodes: ts.NodeArray<ts.Statement>,
270270
parent: ts.SourceFile | ts.Block | ts.ModuleBlock,
271-
): any[] {
271+
): TSESTree.Statement[] {
272272
let allowDirectives = canContainDirective(parent);
273273

274274
return (
@@ -400,7 +400,7 @@ export class Converter {
400400
: null;
401401
} else if (key === 'decorators') {
402402
if (node.decorators && node.decorators.length) {
403-
result.decorators = node.decorators.map((el: any) =>
403+
result.decorators = node.decorators.map(el =>
404404
this.convertChild(el),
405405
);
406406
}
@@ -1340,7 +1340,7 @@ export class Converter {
13401340
}
13411341

13421342
case SyntaxKind.Parameter: {
1343-
let parameter: any;
1343+
let parameter: TSESTree.RestElement | TSESTree.BindingName;
13441344
let result: TSESTree.RestElement | TSESTree.AssignmentPattern;
13451345

13461346
if (node.dotDotDotToken) {
@@ -1349,7 +1349,7 @@ export class Converter {
13491349
argument: this.convertChild(node.name),
13501350
});
13511351
} else if (node.initializer) {
1352-
parameter = this.convertChild(node.name);
1352+
parameter = this.convertChild(node.name) as TSESTree.BindingName;
13531353
result = this.createNode<TSESTree.AssignmentPattern>(node, {
13541354
type: AST_NODE_TYPES.AssignmentPattern,
13551355
left: parameter,
@@ -1584,7 +1584,7 @@ export class Converter {
15841584

15851585
case SyntaxKind.PrefixUnaryExpression:
15861586
case SyntaxKind.PostfixUnaryExpression: {
1587-
const operator = (getTextForTokenKind(node.operator) ?? '') as any;
1587+
const operator = getTextForTokenKind(node.operator) ?? '';
15881588
/**
15891589
* ESTree uses UpdateExpression for ++/--
15901590
*/

packages/typescript-estree/src/node-utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,11 @@ export function isOptional(node: {
450450
* @param token the ts.Token
451451
* @returns the token type
452452
*/
453-
// ts.Node types are ugly
454-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
455-
export function getTokenType(token: any): AST_TOKEN_TYPES {
453+
export function getTokenType(
454+
token: ts.Identifier | ts.Token<ts.SyntaxKind>,
455+
): AST_TOKEN_TYPES {
456456
// Need two checks for keywords since some are also identifiers
457-
if (token.originalKeywordKind) {
457+
if ('originalKeywordKind' in token && token.originalKeywordKind) {
458458
switch (token.originalKeywordKind) {
459459
case SyntaxKind.NullKeyword:
460460
return AST_TOKEN_TYPES.Null;
@@ -572,7 +572,7 @@ export function convertToken(
572572
loc: getLocFor(start, end, ast),
573573
};
574574

575-
if (newToken.type === 'RegularExpression') {
575+
if (newToken.type === AST_TOKEN_TYPES.RegularExpression) {
576576
newToken.regex = {
577577
pattern: value.slice(1, value.lastIndexOf('/')),
578578
flags: value.slice(value.lastIndexOf('/') + 1),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy