内容简介:The TypeScript team announced theWhile the importing and exporting of types would often work because of import elision, ambiguity occurred when it was unclear if it was a type or value getting imported. Import statements that only contained imports used as
The TypeScript team announced the release of TypeScript 3.8 , which includes type-only imports and exports, private fields, and top-level await.
While the importing and exporting of types would often work because of import elision, ambiguity occurred when it was unclear if it was a type or value getting imported. Import statements that only contained imports used as types would get eliminated by TypeScript's import elision. To work around these issues, TypeScript 3.8 adds a new syntax for importing and exporting types:
import type { SomeThing } from "./some-module.js"; export type { SomeThing };
The import type
statement only imports declarations to use for type annotations and declarations and always gets fully erased during transpilation. The export type
command only provides an export for type contexts, also getting erased from TypeScript’s output. When using import type
to import a class, the class cannot get extended.
The TypeScript compiler introduces a new flag, importsNotUsedAsValues
, to determine what happens to imports not used at run-time. The values for this flag, remove
, preserve
, or error,
provide developers with more control over importing and exporting types.
The ECMAScript private fields proposal recently reached stage 3 due to significant efforts from Bloomberg and the TypeScript team.
Private fields start with a # character and get uniquely scoped to their containing class. TypeScript modifiers like public or private cannot get used on private fields. Private fields cannot get accessed or detected outside of the containing class.
Private fields are different than the TypeScript private keyword. As explained by Daniel Rosenwasser, program manager of the TypeScript team:
When it comes to properties, TypeScript’s private modifiers are fully erased – that means that while the data will be there, nothing is encoded in your JavaScript output about how the property was declared. At runtime, it acts entirely like a normal property. That means that when using the private keyword, privacy is only enforced at compile-time/design-time, and for JavaScript consumers, it’s entirely intent-based. The upside is that this sort of “soft privacy” can help your consumers temporarily work around not having access to some API, and works in any runtime. On the other hand, ECMAScript’s # privates are completely inaccessible outside of the class.
Note that TypeScript currently only supports private fields transpilation to ES6 and higher as the backward-compatible implementation leverages WeakMaps, whereas the private keyword works back to ES3.
ECMAScript 2020 adds export *
syntax to expose all members of a module as a single member. Previously developers would need to use this syntax:
import * as utilities from "./utilities.js"; export { utilities };
With ECMAScript 2020 and TypeScript 3.8, this gets reduced to:
export * as utilities from "./utilities.js";
The introduction of promises in ES6 provided the foundation for better asynchronous handing in JavaScript, but has led to many additional features in the five years since its initial release, such as async/await. The latest addition is top-level await, which allows await
at the top level of a module.
Top-level await is now also supported by TypeScript 3.7, though only can get transpiled to ES2017 and newer environments, and the modules support is esnext
or system
, as it requires an environment with ES module support.
TypeScript 3.8 now supports es2020
as a transpilation target and module option. This mode preserves the ES2020 features added inTypeScript 3.7 and 3.8.
The TypeScript 3.8 release improves its directory watching support and adds a new watchOptions
compiler configuration field. These options give developers greater control over how directories and files get watched, improving performance and reliability in working with changes to node_modules
.
The watchOptions
field provides four new options: watchFile
, watchDirectory
, fallbackPolling
, and synchronousWatchDirectory
, each of which has several configuration options for how often to check files and directories.
The TypeScript 3.8 compiler also includes a new compiler performance optimization option, assumeChangesOnlyAffectDirectDependencies
, which tells TypeScript only to recheck and rebuild files that have changed as well as files that directly import them.
With each TypeScript release, the compiler introduces breaking changes as its type checking capabilities improves. In TypeScript 3.8, the compiler adds stricter assignability checks to unions with index signatures.
In the TypeScript community, after two TSConf events in Seattle in 2018 and 2019, the first TSConf Japan and TSConf.eu events are occurring in February and March.
TypeScript is open source software available under the Apache 2 license. Contributions and feedback are encouraged via the TypeScript GitHub project and should follow the TypeScript contribution guidelines and Microsoft open-source code of conduct .
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
算法艺术与信息学竞赛
刘汝佳 / 清华大学出版社 / 2004-1 / 45.00元
《算法艺术与信息学竞赛》较为系统和全面地介绍了算法学最基本的知识。这些知识和技巧既是高等院校“算法与数据结构”课程的主要内容,也是国际青少年信息学奥林匹克(IOI)竞赛和ACM/ICPC国际大学生程序设计竞赛中所需要的。书中分析了相当数量的问题。 本书共3章。第1章介绍算法与数据结构;第2章介绍数学知识和方法;第3章介绍计算机几何。全书内容丰富,分析透彻,启发性强,既适合读者自学,也适合于课......一起来看看 《算法艺术与信息学竞赛》 这本书的介绍吧!