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
However, if you explicitly specify the return type void in the implementation; it works!
varobj : Person={name : "Santi",lastName : "Aguilar",greet : function(person) : void{return"some string";//Type string is not assignable to type void.}}
The text was updated successfully, but these errors were encountered:
There is no bottom type until TypeScript 2.0. Therefore void in an interface is essentially saying "you should ignore a return value from a function. But just like excess parameters, TypeScript evaluates if the resulting object can be conformed to the shape of the interface. So the below is valid (although a bit surprising):
But then of course if you were to depend upon the return type TypeScript would get upset:
functionbar(c: string){console.log(c);}bar(foo.foo());// error here
In TypeScript 2.0 we get the bottom type never, which is a hard "this will NEVER return a value" versus a soft "don't depend upon any returned value" and some more strictness around unused parameters which will allow us to enforce these contracts more specifically.
TypeScript Version: 1.8.10
Hi, I have this code and as you can see the function greet has a return type of void.
Code
Expected behavior:
Type string is not assignable to type void.
Actual behavior:
No error.
However, if you explicitly specify the return type void in the implementation; it works!
The text was updated successfully, but these errors were encountered: