-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [no-unsafe-return] number returned in a
10000
callback of sort
is reported as unsafe any
#5364
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
Comments
sort
sort
is reported as unsafe any
Huh, very weird! This also happens if you simplify the code just a bit to always const xs = ['a', 'b'];
xs.sort((a, b) => {
const compared = a.localeCompare(b);
return compared; // Unsafe return of an `any` typed value.
}); |
This looks like a bug in TS? However i can't reproduce this on the playground... very strange. |
Ok, taking a deeper look, this looks to be a similar -or even the same- root issue as #4689 -> microsoft/TypeScript#48313. Marking as external for now. |
I'm having an issue that's a bit more complex, but might be the same thing as this. Here's my reproduction repo: https://github.com/awesomeunleashed/ts-eslint-unsafe-bug-repro You can see the error in the README there. In my actual code I started getting random If you guys could look if my case looks the same as the TS bug or like I should open a different issue when you have the time, that would be appreciated! |
Also ran into this with similar (simplified) code:
Hovering over in VSCode shows the correct types though. |
On the latest TS version, this doesn't seem to be an error anymore. |
Uh oh!
There was an error while loading. Please reload this page.
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=4.7.2&jsx=true&sourceType=module&code=MYewdgzgLgBAHhGBeGBtA5AQ3QGhugI3QF0BuAKHIQDoIQAnKACiczwIEpkA+GAb3IwYoSLFABbAA6Z6AUwAmyGJmoAbEMEyrZAYRBSZsppwqCYcqAFd6YYfulz5pGAHoXMAKqRMAM1nnZKxsYEB9lWwADTDAATwiYKBjJBRgANy1LWWoYcgBfDnIgA&eslintrc=N4KABGBEAOCGBOBnApvSAuKABALgT2mUQGN4BLaHAWiIBsyA7HAejiVUgBpwp4BXWkQxhQECJFwEipCtTqMWDAPZU+DRLABmyKvGQ4+8BsMgB3BMZ4BfEFaA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A
Repro Code
ESLint Config
tsconfig
Expected Result
As the tooltip on hover states that
compared
is a number, andlocaleCompare
returns a number, I expect TypeScript ESLint rules to know it is in fact a number.Actual Result
no-unsafe-return
reports thatcompared
is any.Additional Info
Versions
@typescript-eslint/eslint-plugin
5.30.7
@typescript-eslint/parser
5.30.7
TypeScript
4.7.2
ESLint
8.15.0
node
web
,16
Edited to include JoshuaKGoldberg's simplified repro.
The text was updated successfully, but these errors were encountered: