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

style: use unknown in try/catch #7709

Merged
merged 9 commits into from
Mar 6, 2024
Merged

style: use unknown in try/catch #7709

merged 9 commits into from
Mar 6, 2024

Conversation

zkochan
Copy link
Member

@zkochan zkochan commented Feb 24, 2024

No description provided.

} catch (err: any) { // eslint-disable-line
if (err.code === 'ENOENT') return null!
} catch (err: unknown) {
if (err instanceof Error && 'code' in err && err.code === 'ENOENT') return null!
Copy link
Contributor

Choose a reason for hiding this comment

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

So this return null! would have type never, which would mean that readCurrentLockfile has a non-null return type despite the fact that it can return null in reality?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't care about it in this PR. This was like this already.

@zkochan
Copy link
Member Author

zkochan commented Mar 3, 2024

Looks like when code is executed by Jest, err instanceof Error returns false. Without jest, my changes work. Looks like in the Jest runtime errors are broken.

Found the solution: https://twitter.com/andhaveaniceday/status/1764442399538131039

@zkochan zkochan force-pushed the style-unknown-in-catch branch from 18df7eb to 702091a Compare March 4, 2024 01:16
@zkochan zkochan merged commit 0564745 into main Mar 6, 2024
14 checks passed
@zkochan zkochan deleted the style-unknown-in-catch branch March 6, 2024 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants