React, etc. Tech Stack

React, Flux, GraphQL, Hack, HHVM...? All of this and more!

Conditional Types arriving in TypeScript 2.8

In a recent Pull Request of TypeScript an interesting feature is coming to the language in 2018. Conditional Typing allows defining types based on conditions, adding more flexibility to the JavaScript based language.

When using conditional types developers can select between two types based on a condition expression. Performing a type relationship test is done with the following syntax:

T extends U ? X : Y

In the example T can be assigned to U if the type is X, but in any case the type has to be Y. The conditional type evaluation is deferred if type variables T or U are in use. Without them it is resolved as X or Y when there is no dependency on a type variable.

Learn more about the feature and more examples in the Pull Request on GitHub: Conditional types #21316

Written by Jorgé on Saturday January 20, 2018

Permalink - Tag: typescript

« Rejoiner creates a GraphQL schema from microservices - WebAssembly vs JavaScript - Streaming Compilation Performance Advantage »