-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
tests(ast-spec): make PunctuatorTokenToText
more type-safe
#3529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the PR, @MichaelDeBoey! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
Nx Cloud ReportCI ran the following commands for commit 5ef6efb. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch
Sent with 💌 from NxCloud. |
@bradzacher @JamesHenry Do you have any idea how I can make this error out as explained in the above message? Would love to work on this one further, but don't see a solution right away. |
can you do something similar to what I did in this? typescript-eslint/packages/ast-spec/tests/ast-node-types.test.ts Lines 1 to 16 in e2e76a7
|
Codecov Report
@@ Coverage Diff @@
## master #3529 +/- ##
==========================================
- Coverage 92.64% 92.63% -0.01%
==========================================
Files 326 325 -1
Lines 11253 11236 -17
Branches 3171 3168 -3
==========================================
- Hits 10425 10409 -16
+ Misses 368 367 -1
Partials 460 460
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@bradzacher I don't see directly how I can use the mentioned test in my use-case tbh. 🤔 A bit more context (or even the test if you like) would be welcome. |
// @ts-expect-error: purposely unused
type _AllKeys = {
// no error as all PunctuationSyntaxKind are covered
readonly [T in PunctuationSyntaxKind]: PunctuatorTokenToText[T];
};
// example showing if we miss one of the PunctuationSyntaxKind
interface AccidentallyIncomplete {
[SyntaxKind.CaretEqualsToken]: '^=';
}
// @ts-expect-error: purposely unused
type _AllKeysError = {
readonly [T in PunctuationSyntaxKind]: AccidentallyIncomplete[T];
// ^^^^^^^^^^^^^^^^^^^^^^^^^ error: Type 'T' cannot be used to index type 'AccidentallyIncomplete'.
} |
@bradzacher The problem is, it should already error out as |
i forgot to delete it when I copy pasted - but delete the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks for thsi!
PunctuatorTokenToText
more type-safePunctuatorTokenToText
more type-safe
Follow-up of #3496
We should somehow test that all possible values of
PunctuationSyntaxKind
are definitely included.If not, this should error out somehow.
I first tried doing
and this errored out (as expected) because
SyntaxKind.BacktickToken
isn't includes, but is included inPunctuationSyntaxKind
.Not including the type makes it also of type
string
again, which will fail #3461 & #3462.This however made it a value instead of a type and had the implication that
SyntaxKind.BarBarEqualsToken
,SyntaxKind.AmpersandAmpersandEqualsToken
&SyntaxKind.QuestionQuestionEqualsToken
couldn't be added as they'll only be added toPunctuationSyntaxKind
in TS 4.4 (they're currently included onmain
).In TS 4.4 the new
SyntaxKind.HashToken
should also be included, so I think it would be nice to have it somehow error out if we don't include that when updating our TS version.@bradzacher @JamesHenry Any idea how I can make this error out when some values aren't included or how I should write a test that can fail when a new value isn't included here?