-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Anonymous Function Type Not Constraining Object Return Value #59586
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 as intended. Your function lacks a return type annotation, so the return type is inferred. The inferred type is then checked for assignability, where excess property checks don't happen anymore. There are many issues about this. |
Duplicate #241 and others |
I tried to remove annotation for parameter at anonymous function type AF = (param: ParamValue) => ReturnValue;
const af: AF = (param) => {
return {
r: param.p,
// @ts-expect-error
error: "error",
};
};
af({
p: 0,
// @ts-expect-error
error: "error"
}) |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
anonymous function type, return object value
π Version & Regression Information
Same behavior for version 3.9.7, 4.9.5, 5.5.4, 5.6.0-beta and v5.6.0-dev.20240810.
β― Playground Link
https://www.typescriptlang.org/play/?jsx=0&ts=5.5.4#code/C4TwDgpgBAShwFcBOA7AagQwDYOgXigG8okAuKFBAWwCMIkoBfAKFEigAUMkMrMd8RKGHKVa9Js2YAzBCgDGwAJYB7FFGkAKMN17kuPPtlwBKcnESp+uIswCQSeMnWF7D8jsMA6MABo3APQBUAACwADOALQQAB6QitFISCpIbvTJZFAAROkpWf52jADczCxarlCVwuQADAVBoRHRcRAJualVUO3kOUl5pSZSbNAAggBiUATaulT6M9YQJpMAfLBOVsYQJfJq4cBQGNLk45NQ04akBrwLS3irrg7rLm6Znrw+BXYNYVGx8cCJDJpPqZXoZfL2YqlEqHTQVKoiKB1ezfJp-VoA9rMTrdbLtLIDIA
π» Code
π Actual behavior
At third
// @ts-expect-error
(return object of functionaf
) giving error because it's not used. Since there is no error at that line.π Expected behavior
Typescript should give error about extraneous
error
property, since for non-anonymous type functionf
gave that error. This same error happen for parameter of bothaf
andf
function. I assume this should be the case for return value too.The text was updated successfully, but these errors were encountered: