How TypeScript distributes unions

In the past few weeks I've been writing a little library in TypeScript, and I've learned a lot about the type system in the process. This is the first article, which focuses on how TypeScript deals with unions. Does this typecheck? And if it does, what is the type of x ? function foo ( it : string ): string function foo ( it : number ): number function foo ( it : number | string ): number | string…