Skip to content

docs: [no-unsafe-call] clarify that you can never safely narrow Function #10058

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

Merged

Conversation

kirkwaiblinger
Copy link
Member

@kirkwaiblinger kirkwaiblinger commented Sep 25, 2024

PR Checklist

Overview

Followup to #9108 (comment)

cc @controversial feel free to chime in with your thoughts!

Co-authored-by: @controversial

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @kirkwaiblinger!

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 Sep 25, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit d1bb0bd
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66f9dbbca45b460008785289
😎 Deploy Preview https://deploy-preview-10058--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: 99 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (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.

Copy link

nx-cloud bot commented Sep 25, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d1bb0bd. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@controversial
Copy link
Contributor

This looks great!

I think the key clarification for me would be something explicit along the lines of “there is no safe way to narrow a value whose type you don’t know into something that’s safe to call”

Maybe it would also be valuable to suggest type assertion within the try/catch as a preferred workaround to suppressing the lint rule? like:

try {
  (maybeFunction as () => void)();
} catch (e) {
  console.error(
    'Function either could not be called or threw an error when called:',
    e,
  );
}

since this way, you still let no-unsafe-call check that it would be safe to call the function if it had the type you expect it to have

but I think as-is, the PR is a great improvement to the docs for this new case

@kirkwaiblinger kirkwaiblinger marked this pull request as ready for review September 29, 2024 19:21
@kirkwaiblinger
Copy link
Member Author

@controversial Good suggestions! I've updated it, and pared down the extraneous information 👍

Copy link

codecov bot commented Sep 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.01%. Comparing base (a916ff2) to head (2a0cbf5).
Report is 23 commits behind head on main.

Current head 2a0cbf5 differs from pull request most recent head d1bb0bd

Please upload reports for the commit d1bb0bd to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10058      +/-   ##
==========================================
+ Coverage   85.99%   86.01%   +0.02%     
==========================================
  Files         428      427       -1     
  Lines       14912    14892      -20     
  Branches     4332     4329       -3     
==========================================
- Hits        12823    12810      -13     
+ Misses       1744     1736       -8     
- Partials      345      346       +1     
Flag Coverage Δ
unittest 86.01% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 8 files with indirect coverage changes

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.

🆒

@JoshuaKGoldberg JoshuaKGoldberg merged commit 656a36e into typescript-eslint:main Oct 10, 2024
60 checks passed
@kirkwaiblinger kirkwaiblinger deleted the unsafe-function-call branch October 10, 2024 19:49
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants