Skip to content

fix(type-utils): preventing isUnsafeAssignment infinite recursive calls - #8237

Merged
JoshuaKGoldberg merged 2 commits into
typescript-eslint:mainfrom
yeonjuan:fix/7298
Jan 16, 2024
Merged

JoshuaKGoldberg merged 2 commits into
typescript-eslint:mainfrom
yeonjuan:fix/7298

Conversation

@yeonjuan

@yeonjuan yeonjuan commented Jan 11, 2024 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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.

@netlify

netlify Bot commented Jan 11, 2024 •

Copy link
Copy Markdown

✅ 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

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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 >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge 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

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Copy link
Copy Markdown
Member

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
@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 >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge

Projects

None yet

2 participants