简体   繁体   English

TypeScript 中的类型级扩展是什么?

[英]What are type-level extensions in TypeScript?

While reading the TypeScript handbook, I came across the first sentence at the top of the page on enums :在阅读 TypeScript 手册时,我遇到了enums 页面顶部的第一句话:

Enums are one of the few features TypeScript has which is not a type-level extension of JavaScript.枚举是 TypeScript 拥有的少数功能之一,它不是 JavaScript 的类型级扩展。

What does this mean?这是什么意思? What is a type-level extension?什么是类型级扩展?

TypeScript was designed from the ground up to be a superset of Javascript, with the intention to have no runtime impact. TypeScript 从一开始就被设计为 Javascript 的超集,旨在不影响运行时。

The design goals document should give you a pretty good idea of what design principles TypeScript is based on. 设计目标文档应该让您很好地了解 TypeScript 所基于的设计原则。

Pretty much everything you write in TypeScript which has to do with types (another way to put it is, everything that wouldn't be valid JS syntax) is only used by tsc at compile time, but disappears at runtime.您在 TypeScript 中编写的几乎所有与类型有关的东西(另一种说法是,所有不是有效的 JS 语法)仅在编译时由 tsc 使用,但在运行时消失。

enums are an exception to that, as they actually result in some JS code being produced and used at runtime . enums是一个例外,因为它们实际上会导致在运行时生成和使用一些 JS 代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM