-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [no-misused-promises] Possible false positive in 5.27.0 #5121
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
this is working correctly -> it should warn you about this, currently you are casting awaited value to Promise const data = await dataGetValidate({userid}) as Promise<dataType | null>; this code is interpreted as const data = (await dataGetValidate({userid})) as Promise<dataType | null>; Solution: - const data = await dataGetValidate({userid}) as Promise<dataType | null>;
+ const data = await (dataGetValidate({userid}) as Promise<dataType | null>); i copied your tsconfig to be able to reproduce this see repro |
This comment was marked as off-topic.
This comment was marked as off-topic.
@armano is correct! await (thing as Promise) you have (await thing) as promise The rule is working correctly and has caught a bug in your code! |
@armano2 Thank you for you feedback. I understand and was actually thinking the same but when using |
This comment was marked as off-topic.
This comment was marked as off-topic.
@armano2 Thank you. I must somehow have removed the target and then missed to put it back. |
@doberkofler for sure! next time if you could filter out the non-ts-eslint rules that'd go a long way.
Your code should be
not
The former code you are "casting" it to a promise and then awaiting it (i.e. your result will be of type Here's a playground to better show the correct parenthisation |
@bradzacher I understand but when using the proper parentheses (sorry but I just copied the wrong code before) I get |
That's a bug in the |
Thank you! Now I fully understand and sorry for not digging deeper before opening the SR. It seems I somehow just wanted it to be related to the improved |
Should I open a new SR or ... ? |
I just filed one on your behalf! #5124 |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=4.7.2&sourceType=module&code=C4TwDgpgBAJghsOAVc0C8UDeBXAzhAJwEsYAuKAO2wFsAjQgXwG4AoFgM2woGNgiB7CrARwA4hGAA1OABsSCCAAowcAnAD85AEoRu-AjAA8uYMQoBzADRQuAawr8A7hQB8UAD6VsMmQEpyAAoE-NRE+IZ2Ds5umCxQUAQS2ARCQSFhEAB0ibj8MgBuSipqvqwMbBAAHmD6wFBwuCA8UJw8fIJQ+DKKeIQk5FR0hP5QaaHh8IgokB5ePjFxUHoUJsKIUBhwjnBEdZNiEtJyk0o4+MQwDL71uKPB4xCG+9PQnlTzrPFE7FCK+1AAQjQGHefiwi3iiWAySEsXi8KgmSR+0sEKgzEW5UWUJhcxkZRYQA&eslintrc=N4KAkARApgHgLlAdgEwM4QFwAIDa5IAOANgK4DmAlohgAJwCeBUqAxgE4UFwC0zRVcAPR8B3NlBYB7ALbSkyKMggAafBGLkqtBk1YcuvVP0RCAhkSIQQWLAF1VNiGxJFmmLKBuO6jZu048IiaCiJLc0hSoJKiK3ARsMpFu2HheXtBsCWwq1mkeuXlYECwAFhIA1qgAapIUyABKUHAkbIjuAGbmMQVeAL49ttb9vUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA
Repro Code
ESLint Config
tsconfig
Expected Result
I would not expect the warning (this still worked in version 5.26.0)
Actual Result
The warning
Expected a non-Promise value to be spreaded in an object @typescript-eslint/no-misused-promises
in shown since the upgrade to version 5.27.0Additional Info
Unfortunately, I was not able to reproduce the error in the playground
Versions
@typescript-eslint/eslint-plugin
5.27.0
@typescript-eslint/parser
5.27.0
TypeScript
4.7.2
ESLint
8.16.0
node
18.1.0
The text was updated successfully, but these errors were encountered: