-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
version 4.17.1,the type of the data variable is inferred to never by _.has #69528
Comments
I'm surprised it narrows the type to I'm guessing the issue is that Why do you need to use |
Ah, I just noticed #69534 which should fix this. |
its historical code,cause compilation error after upgrade to 4.17.1. |
This issue is still not solved in version 4.17.4 import _ from "lodash";
function test(doc: any) {
if (_.has(doc, "something")) {
}
else {
doc["something"] = true;
}
} This code will trigger "TS2322: Type 'boolean' is not assignable to type 'never'." |
That seems like reasonable behavior IMHO - if TS thinks the propery doesn't exist then it won't let you set it. If you want to treat the object as a map, use something like |
equivalent non lodash code doesn't give an error: function test(doc: any) {
if (doc.hasOwnProperty("something")) {
}
else {
doc["something"] = true;
}
} the type of doc is "any", why would _.has change that? not sure it's lodash job to "discipline" developers, so shouldn't be too opinionated regarding the use of "any". Anyway this is a breaking change, as that was not the behavior prior to version 4.17.1 |
issue:
on 4.17.1 version,the type of the data variable is inferred to never by _.has。
source of problem:
#69291
1c01676#diff-0740e38db2dd38b18fb8612ceef08349585a3d898fb6ad21522819b8677804f7
The text was updated successfully, but these errors were encountered: