TypeScript: Why is this not a type error?

I am trying to understand the degree of type inference when working in TypeScript. In the following code example, why is foo implementation of baz.esplode valid? I understand that an empty method matches void .

 interface bar { horace: number; } interface baz { esplode: (string, number) => bool; } interface bazzer extends bar, baz { } var foo: bazzer = { horace: 12, esplode: function () { } } var x = foo.esplode('crackers', 2); 

Thanks!

+6
source share
1 answer

thanks for watching!

This is actually a mistake. When a function is contextually introduced, we should consider it as if there were an annotation of the return type that represents the intended return type (in section 4.9 of the language specification), so you are correct that there should be an error.

I already have a fix for this, but can you register a bug on the CodePlex website so our team can track it? Today I can push the correction to our development industry.

Thanks again!

+11
source

Source: https://habr.com/ru/post/926732/


All Articles