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(type-utils): preventing isUnsafeAssignment infinite recursive calls #8237

Merged
merged 2 commits into from Jan 16, 2024

Conversation

yeonjuan
Copy link
Contributor

@yeonjuan yeonjuan commented Jan 11, 2024

PR Checklist

Overview

This PR prevents infinite recursive calls to isUnsafeAssignment for code with circular references.

no-unsafe-argument ( #7298, #5014)

playground

type T = [number, T[]];
declare function foo(t: T): void;
declare const t: T;

foo(t);
RangeError: Maximum call stack size exceeded
...

no-unsafe-assignment (unreported issue)

playground

type T = [string, T[]];
const test: T = ['string', []] as T;
RangeError: Maximum call stack size exceeded
..

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @yeonjuan!

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.

Copy link

netlify bot commented Jan 11, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit a84ed04
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/65a5361bdc580f0007a82cbb
😎 Deploy Preview https://deploy-preview-8237--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 89 (🔴 down 7 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@yeonjuan yeonjuan changed the title fix(type-utils): Preventing isUnsafeAssignment infinite recursive calls fix(type-utils): preventing isUnsafeAssignment infinite recursive calls Jan 11, 2024
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the double-fix! 🚀 🚀

Just suggesting changes for the one refactor. If I missed something on it then no worries we can ship as-is.

Comment on lines 23 to 39
visited = new Map<ts.Type, Set<ts.Type>>(),
): false | { sender: ts.Type; receiver: ts.Type } {
Copy link
Member

Choose a reason for hiding this comment

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

[Refactor] This code works great as-is, but has a couple of little paper cuts IMO:

  • Each call now has to check whether visited exists (this is not really a big issue at all, certainly not a blocker)
  • Callers now can see this visited Map even though there's no reason for them to provide it

What do you think about making a non-exported worker function so the public signature doesn't need to have visited?

  senderNode: TSESTree.Node | null,
): false | { sender: ts.Type; receiver: ts.Type } {
  return isUnsafeAssignmentWorker(type, receiver, checker, senderNode, new Map());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about making a non-exported worker function so the public signature doesn't need to have visited?

I think it's much better. let me refactor it! :)

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready labels Jan 11, 2024
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Jan 15, 2024
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Rachel Brosnahan on a boat as The Marvelous Mrs. Maisel. Relaxed, in sunglasses with a drink. Caption: "THIS IS GLORIOUS"

@JoshuaKGoldberg JoshuaKGoldberg merged commit 01556f5 into typescript-eslint:main Jan 16, 2024
55 of 57 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready
Projects
None yet
2 participants