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
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.
TypeScript Version: 3.0.1-insiders.20180726
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 ifvalidKey
is removed. It's as if type checking on the return type has widened.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.
Playground Link
Related Issues:
The text was updated successfully, but these errors were encountered: