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
interfaceTestInterface{testValue: boolean;}lettestFunc: ()=>TestInterface;// Compiler allows returning unknown propertiestestFunc=function(){return{testValue: true,otherValue: 7};}// When the return type is explicitly specified, compiler warns about unknown propertiestestFunc=function(): TestInterface{return{testValue: true,otherValue: 8};}
Expected behavior:
Since the testFunc has type annotation that specifies return value TestInterface, I expect that I will be able to return only objects with properties specified in TestInterface. However, the compiler allows me to return properties not specified in TestInterface.
To achieve my expected behavior, I need to explicitly specify the function return value. I think the compiler should be able to infer this from the type annotation.
Actual behavior:
Compiler does not complain about unknown object properties.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.6.2
Code
Playground
Expected behavior:
Since the
testFunc
has type annotation that specifies return valueTestInterface
, I expect that I will be able to return only objects with properties specified inTestInterface
. However, the compiler allows me to return properties not specified inTestInterface
.To achieve my expected behavior, I need to explicitly specify the function return value. I think the compiler should be able to infer this from the type annotation.
Actual behavior:
Compiler does not complain about unknown object properties.
The text was updated successfully, but these errors were encountered: