从类型创建类型

TypeScript 的类型系统非常强大,因为它允许用其他类型来表达类型。

¥TypeScript’s type system is very powerful because it allows expressing types in terms of other types.

这个想法的最简单形式是泛型。此外,我们还有各种各样的类型运算符可供使用。也可以用我们已经拥有的值来表达类型。

¥The simplest form of this idea is generics. Additionally, we have a wide variety of type operators available to use. It’s also possible to express types in terms of values that we already have.

通过组合各种类型的操作符,我们可以用简洁、可维护的方式表达复杂的操作和值。在本节中,我们将介绍根据现有类型或值来表达新类型的方法。

¥By combining various type operators, we can express complex operations and values in a succinct, maintainable way. In this section we’ll cover ways to express a new type in terms of an existing type or value.