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
Functional Types / Interfaces: Return Type Widening #27237
Search Terms: function type interface return widening
This seems like an incredibly basic problem compared to others I've searched for so I apologize in advance if I'm missing some expected behavior with regards to functional types and interfaces.
Code
This code properly analyzes return type and generates an error when invalidKey is present.
However, when this declaration is elevated to a functional type or interface, return type appears to widen and this error no longer appears. Basic IReturn type checking seems to be present as there will be an error if validKey is removed. It's as if type checking on the return type has widened.
// Arrow Function TypetypeIArrowFunction=(props: IArg)=>IReturn;constshouldGenerateError1: IArrowFunction=(props)=>{return{validKey: 1,invalidKey: 2// should error};};
// Function InterfaceinterfaceIFunction{(a: IArg): IReturn;}constshouldGenerateError2: IFunction=function(props){return{validKey: 1,invalidKey: 2// should error};};
Expected behavior:
Functional types and interfaces type check return value in the same manner as inline functional typing.
Actual behavior:
Functional types and interfaces do not have the same return type checking as inline functional typing.
Activity
RyanCavanaugh commentedon Sep 20, 2018
Duplicate #241
typescript-bot commentedon Dec 14, 2018
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.