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
interfaceEmptyInterface{}interfaceNonemptyInterface{_?: unknown}interfaceSomeOtherInterface{x?: string;}typeObjectOrCallback<T>=|(SomeOtherInterface&T)|(()=>(SomeOtherInterface&T));// @ts-expect-errorconsta: ObjectOrCallback<EmptyInterface>={excessProp: 1};constfa: ObjectOrCallback<EmptyInterface>=()=>({excessProp: 1});// why doesn't this cause an error too?// @ts-expect-errorconstb: ObjectOrCallback<NonemptyInterface>={excessProp: 1};// @ts-expect-errorconstfb: ObjectOrCallback<NonemptyInterface>=()=>({excessProp: 1});
π Actual behavior
The function fa, which is defined as having the return type { x?: string } & {} can return an object with extra properties, whereas function fb, having the return type { x?: string } & { _?: unknown} cannot. This seems to be inconsistent.
π Expected behavior
Since both EmptyInterface & SomeOtherInterface and NonemptyInterface & SomeOtherInterface are types with optional properties only, both fa and fb should not allow excess properties on their return type.
The text was updated successfully, but these errors were encountered:
Because your function has no return type annotation, so the return type is inferred. Then the type of your function is checked for assignability, in which case excess property checks are not occurring anymore. This is working as intended, and there are numerous issues about this.
Bug Report
π Search Terms
excess, extra
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The function
fa
, which is defined as having the return type{ x?: string } & {}
can return an object with extra properties, whereas functionfb
, having the return type{ x?: string } & { _?: unknown}
cannot. This seems to be inconsistent.π Expected behavior
Since both
EmptyInterface & SomeOtherInterface
andNonemptyInterface & SomeOtherInterface
are types with optional properties only, bothfa
andfb
should not allow excess properties on their return type.The text was updated successfully, but these errors were encountered: