Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abda961

Browse files
tests(ast-spec): make PunctuatorTokenToText more type-safe (typescript-eslint#3529)
1 parent 44f9c07 commit abda961

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/ast-spec/src/token/PunctuatorToken/PunctuatorTokenToText.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export interface PunctuatorTokenToText {
4444
[SyntaxKind.ColonToken]: ':';
4545
[SyntaxKind.AtToken]: '@';
4646
[SyntaxKind.QuestionQuestionToken]: '??';
47+
[SyntaxKind.BacktickToken]: '`';
48+
// [SyntaxKind.HashToken]: '#'; // new in PunctuationSyntaxKind in TS 4.4
4749
[SyntaxKind.EqualsToken]: '=';
4850
[SyntaxKind.PlusEqualsToken]: '+=';
4951
[SyntaxKind.MinusEqualsToken]: '-=';
@@ -56,8 +58,8 @@ export interface PunctuatorTokenToText {
5658
[SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken]: '>>>=';
5759
[SyntaxKind.AmpersandEqualsToken]: '&=';
5860
[SyntaxKind.BarEqualsToken]: '|=';
59-
[SyntaxKind.BarBarEqualsToken]: '||=';
60-
[SyntaxKind.AmpersandAmpersandEqualsToken]: '&&=';
61-
[SyntaxKind.QuestionQuestionEqualsToken]: '??=';
61+
[SyntaxKind.BarBarEqualsToken]: '||='; // included in PunctuationSyntaxKind in TS 4.4
62+
[SyntaxKind.AmpersandAmpersandEqualsToken]: '&&='; // included in PunctuationSyntaxKind in TS 4.4
63+
[SyntaxKind.QuestionQuestionEqualsToken]: '??='; // included in PunctuationSyntaxKind in TS 4.4
6264
[SyntaxKind.CaretEqualsToken]: '^=';
6365
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { PunctuationSyntaxKind } from 'typescript';
2+
3+
import type { PunctuatorTokenToText } from '../src';
4+
5+
// @ts-expect-error: purposely unused
6+
type _Test = {
7+
readonly [T in PunctuationSyntaxKind]: PunctuatorTokenToText[T];
8+
// If there are any PunctuationSyntaxKind members that don't have a
9+
// corresponding PunctuatorTokenToText, then this line will error with
10+
// "Type 'T' cannot be used to index type 'PunctuatorTokenToText'."
11+
};

0 commit comments

Comments
 (0)