Hacker News new | ask | show | jobs
by truth_seeker 2560 days ago
I really like the way TypeScript approaches Dynamic world of JS ecosystem with various advance types.

https://www.typescriptlang.org/docs/handbook/advanced-types....

Intersection Types - An intersection type combines multiple types into one.

Union Types - A union type describes a value that can be one of several types

Type Guards - A type guard is some expression that performs a runtime check that guarantees the type in some scope.

Nullable types - compiler level safety for "can be a null " implication of any type

Type alias - as the name suggests

String literal types - Union type of few string values

Numeric literal types - Union type of few numeric values

Enum Member Types - enum members have types when every member is literal-initialized

Discriminated Unions - You can combine singleton types, union types, type guards, and type aliases

Index Types - you can get the compiler to check code that uses dynamic property names

Mapped Types - Transforms each property in the old type in the same way to create new type.

Conditional Types - selects one of two possible types based on a condition expressed as a type relationship test

1 comments

Nice overview! I plan on building a larger version of this into the docs eventually

https://github.com/microsoft/TypeScript/issues/31983#issueco...