Skip to content
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

fix(experimental-utils): fix eslint-utils' negative predicates' return types in ast-utils #3461

Merged
merged 1 commit into from Jun 17, 2021

Conversation

MichaelDeBoey
Copy link
Contributor

Just like it's done with isNotCommentToken

const isNotCommentToken = eslintUtils.isNotCommentToken as (
token: TSESTree.Token,
) => token is Exclude<TSESTree.Token, TSESTree.Comment>;

@typescript-eslint
Copy link
Contributor

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.

@MichaelDeBoey MichaelDeBoey force-pushed the patch-8 branch 2 times, most recently from 12b9c08 to 3547451 Compare June 4, 2021 17:10
@bradzacher bradzacher added the repo maintenance things to do with maintenance of the repo, and not with code/docs label Jun 4, 2021
@bradzacher
Copy link
Member

bradzacher commented Jun 6, 2021

While I definitely like the idea of this, ultimately this doesn't actually do anything.

The type of Token['value'] is string.
Because TypeScript doesn't support exclusions from the primitive types - Excludes<string, '=>'> just results in string.

Exclude<TSESTree.Token, TSESTree.Comment> OTOH does do something as Comment is a distinct type in the union, which can be excluded.

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Jun 6, 2021
@MichaelDeBoey
Copy link
Contributor Author

MichaelDeBoey commented Jun 7, 2021

@bradzacher You think there's another way of getting the correct type then?

Edit: posted https://twitter.com/MichaelDeBoey93/status/1401920255404953604 to get some help

@bradzacher
Copy link
Member

bradzacher commented Jun 7, 2021

There is unfortunately not right now.
There was a TS issue about "negative" types a while back. It's something the TS team has thought about but has not implemented.

Edit: orta dug up the issue: microsoft/TypeScript#29317

@MichaelDeBoey
Copy link
Contributor Author

MichaelDeBoey commented Jun 7, 2021

@bradzacher microsoft/TypeScript#29317 is the issue as mentioned by @orta in https://twitter.com/orta/status/1401934733634846723

So there's no other way to do this then?
Not even when it's a complicated way?

@bradzacher Making the value of PunctuatorToken equal to '=>' | '}' | ']' | ')' | ':' | ',' | '{' | '[' | ... for instance? 🤔

interface PunctuatorToken extends BaseToken {
  type: AST_TOKEN_TYPES.Punctuator;
  value: '=>' | '}' | ']' | ')' | ':' | ',' | '{' | '[' | ...;
}

@bradzacher
Copy link
Member

Correct, but then we would have to attempt to list out every single possible token string and keep it up to date.

Not an impossible task, just a (relatively) low value one.

Also it's not a great thing because custom parsers (babel, Vue, markdown, angular) may add new tokens, which then causes our types to be wrong. By-and-large our rules shouldn't make assumptions about the parser.

@MichaelDeBoey
Copy link
Contributor Author

@bradzacher This PR adds type-safety and type guards for those functions.
I know I'm biased, but I think the "low value maintenance" of the value type is subordinate to the extra value you get from having the type guards I think?

What do you think?
Should we proceed here?

I'm happy to create another PR to update the value type if that's preferred btw.

@nx-cloud
Copy link

nx-cloud bot commented Jun 12, 2021

Nx Cloud Report

CI ran the following commands for commit 0127fc9. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch

Status Command
#000000 nx run-many --target=build --all --parallel
#000000 nx run-many --target=typecheck --all --parallel

Sent with 💌 from NxCloud.

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Jun 13, 2021
@MichaelDeBoey
Copy link
Contributor Author

@bradzacher Now that #3496 is merged, this one can be merged too I think?

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup - looks good now and it should all work!!

@bradzacher bradzacher merged commit 614b0a3 into typescript-eslint:master Jun 17, 2021
@MichaelDeBoey MichaelDeBoey deleted the patch-8 branch June 17, 2021 08:22
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
repo maintenance things to do with maintenance of the repo, and not with code/docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants