TypeScript - What Happens to Compiled Interfaces

InstructorJohn Lindquist

Share this video with your friends

Send Tweet

This lesson covers using your first TypeScript Interface and what happens to the Interface when it is compiled down to JavaScript.

Alexis Sánchez
~ 7 years ago

I am trying to follow your code, but I notice today I have a little differences in my compile, this is the code:

https://gist.github.com/aasanchez/673da80e8dc667332fa7d53fc6b81747

as you can see I have some extra lines of code... I dont know why, I am using webstrom

Jean-Denis Vauguet
~ 6 years ago

By the way, "duck typing" is referred to as structural typing in TypeScript's handbook. It means what matters for a value to be recognized as "of type X" is not the name "X" (that would be nominal typing), but the structure/shape of X. If another type Y provides a structure the value can be matched against, then the value could also be said to be of type Y. TypeScript implements guessing algorithms to pick the "best type" out of context, but sometimes it fails and explicit type annotation help with resolving issues like that, and more.