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
Inferred return types checked against extended (as opposed to specific) declaration's return type. #30096
Search Terms: return types accept extra properties
Code
interfaceIOnlyBob{bob :string};//this errors as we expect//const _errors :IOnlyBob = {bob:'hi', steve:'there'};//this works fine but should errorlet_returnsBob :()=>IOnlyBob;_returnsBob=()=>({bob:'hi',steve:'there'});//I'd expect this to be the way to do the above, if that's what someone actually wantedlet_returnsNotJustBob :<TextendsIOnlyBob>()=>T;_returnsNotJustBob=()=>({bob:'hi',steve:'there'}asany);//have to do any, see https://github.com/Microsoft/TypeScript/issues/28154
Expected behavior:
Line 8 should fail.
Type '{ bob: string; steve: string; }' is not assignable to type 'IOnlyBob'.
Object literal may only specify known properties, and 'steve' does not exist in type 'IOnlyBob'.
Activity
RyanCavanaugh commentedon Feb 27, 2019
Duplicate / root-cause #241
Hashbrown777 commentedon Feb 27, 2019
Oh ta! "Widening", I guess if I knew the lingo I'd've found that.
Thanks, I'll watch that space.