You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Anonymous Function Type Not Constraining Object Return ValueΒ #59586
At third // @ts-expect-error (return object of function af) 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 function f gave that error. This same error happen for parameter of both af and f function. I assume this should be the case for return value too.
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.
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.
I tried to remove annotation for parameter at anonymous function af. So, if it's the case (about lack of annotation), then at last // @ts-expect-error (when calling function af), it should not throwing any error, because the parameter is inferred. But it still throwing the error.
Activity
MartinJohns commentedon Aug 10, 2024
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.
jcalz commentedon Aug 10, 2024
Duplicate #241 and others
atpur-rafif commentedon Aug 11, 2024
I tried to remove annotation for parameter at anonymous function
af. So, if it's the case (about lack of annotation), then at last// @ts-expect-error(when calling functionaf), it should not throwing any error, because the parameter is inferred. But it still throwing the error.typescript-bot commentedon Aug 15, 2024
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.