User Tools

Site Tools


typescript_3.7

TypeScript 3.7

Return to TypeScript Version History, TypeScript, JavaScript


TypeScript 3.7, released in November 2019, brought a significant set of new features and improvements that have had a profound impact on TypeScript development. This version emphasized developer productivity, code quality, and alignment with the latest ECMAScript standards. Below, we explore the key features introduced in TypeScript 3.7, providing examples, comparisons with similar features in other programming languages, and the necessary TypeScript resource links.

- Language Documentation: [TypeScript Documentation](https://www.typescriptlang.org/docs/) - GitHub Repository: [TypeScript GitHub](https://github.com/microsoft/TypeScript) - Official Website: [TypeScript](https://www.typescriptlang.org/) - Wikipedia: [TypeScript Wikipedia](https://en.wikipedia.org/wiki/TypeScript)

  1. Optional Chaining

TypeScript 3.7 introduced optional chaining (`?.`), allowing developers to read the value of a property located deep within a chain of connected objects without having to explicitly validate that each reference in the chain is valid.

```typescript const value = obj?.prop?.subProp; ```

Optional chaining is now part of ECMAScript 2020, making TypeScript align with the latest JavaScript standards. C# has had a similar feature (`?.`) for safely navigating object properties. Java introduced the Optional class in Java 8, which can achieve similar results but with more verbose syntax. Python does not have built-in syntax for optional chaining but can use third-party libraries or custom utility functions.

  1. Nullish Coalescing

TypeScript 3.7 added support for nullish coalescing (`??`), a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.

```typescript const result = value ?? “default value”; ```

Like optional chaining, nullish coalescing is also part of ECMAScript 2020. C# has a similar operator (`??`) that provides the same functionality. Java and Python do not have a direct equivalent built into the language, requiring conditional expressions to achieve similar outcomes.

  1. Assertion Functions

Assertion functions in TypeScript 3.7 provide a way to perform runtime checks and signal to the type system when something is expected to be true. If an assertion fails, the function will throw an exception.

```typescript function assert(condition: any, msg?: string): asserts condition {

   if (!condition) {
       throw new AssertionError(msg);
   }
} ```

While JavaScript does not have built-in assertion functions tied to the type system, libraries such as Chai or Jest are commonly used for assertions in testing. C#'s Debug.Assert and Java's assert keyword offer similar functionality but are not directly integrated with their type systems. Python's assert statement is used for debugging purposes, with no impact on typing.

  1. Better Support for `never`-Returning Functions

TypeScript 3.7 improved the handling of functions that never return (either by throwing an error or by entering an infinite loop), allowing these to be used more effectively in control flow analysis.

```typescript function throwError(errorMsg: string): never {

   throw new Error(errorMsg);
} ```

JavaScript does not have a concept of `never` types, as it is dynamically typed. C#'s `throw` statement and Java's `throw` keyword behave similarly in practice but are not part of the type system. Python's `raise` statement for exceptions does not have a type system equivalent either.

  1. More Recursive Type Aliases

TypeScript 3.7 expanded support for recursive type aliases, allowing developers to more easily type recursive data structures like trees.

```typescript type JsonValue = string | number | boolean | null | JsonArray | JsonObject; type JsonArray = JsonValue[]; interface JsonObject { [key: string]: JsonValue; } ```

Recursive types are a common feature in statically typed languages, though their implementation and support vary. C# and Java support recursive types through classes and interfaces. Python's type hints introduced in PEP 484, and expanded in later PEPs, allow for recursive type hints using strings or `from __future__ import annotations`.

  1. `–declaration` and `–allowJs`

TypeScript 3.7 made it possible to generate .d.ts files from JavaScript files using the `–declaration` flag in conjunction with `–allowJs`, improving interoperability between JavaScript and TypeScript in projects.

This feature is unique to TypeScript as it bridges JavaScript and TypeScript development. C#, Java, and Python do not have an equivalent mechanism because they do not share the same relationship between a statically typed and a dynamically typed version of the language.

  1. Use `declare` on Class Fields

TypeScript 3.7 allowed developers to use the `declare` keyword on class fields, indicating that they will be initialized elsewhere (e.g., in the constructor or by dependency injection).

```typescript class MyClass {

   declare myProperty: string;
} ```

This feature is specific to TypeScript's type system. C# has

similar functionality with its support for uninitialized non-nullable properties. Java and Python require fields to be explicitly initialized or assured to be initialized indirectly (e.g., through constructors).

  1. `// @ts-nocheck` in TypeScript Files

TypeScript 3.7 introduced the `// @ts-nocheck` comment directive, allowing entire TypeScript files to be skipped by the compiler's type checker, useful for gradually migrating JavaScript to TypeScript.

JavaScript files can use `// @ts-ignore` comments for line-by-line suppression of type checking errors, but TypeScript's file-level suppression is unique. C#, Java, and Python do not have direct equivalents since they do not differentiate between type-checked and unchecked code in the same way.

  1. Editor Improvements

TypeScript 3.7 brought numerous editor improvements, such as more accurate auto-completion, better documentation on hover, and quicker fixes for missing imports.

These improvements are specific to TypeScript's tooling and integrated development environments (IDEs). However, IDEs for languages like C#, Java, and Python also continually improve their editing experiences with features like intelligent code completion, inline documentation, and refactorings.

  1. Conclusion

TypeScript 3.7 significantly improved the language's usability and alignment with ECMAScript standards, introducing features like optional chaining, nullish coalescing, and assertion functions that enhance code safety and developer productivity. By comparing these features with those available in other major languages, it's clear that TypeScript provides a unique blend of JavaScript flexibility with the safety and robustness of a statically typed language, making it an attractive choice for developers building complex applications.


TypeScript Version History: TypeScript, JavaScript. TypeScript 4.7 (2022), TypeScript 4.6 (2022), TypeScript 4.5 (2021), TypeScript 4.4 (2021), TypeScript 4.3 (2021), TypeScript 4.2 (2021), TypeScript 4.1 (2020), TypeScript 4.0 (2020), TypeScript 3.9 (2020), TypeScript 3.8 (2020), TypeScript 3.7 (2019), TypeScript 3.6 (2019), TypeScript 3.5 (2019), TypeScript 3.4 (2019), TypeScript 3.3 (2019), TypeScript 3.2 (2018), TypeScript 3.1 (2018), TypeScript 3.0 (2018), TypeScript 2.9 (2018), TypeScript 2.8 (2018), TypeScript 2.7 (2018), TypeScript 2.6 (2017), TypeScript 2.5 (2017), TypeScript 2.4 (2017), TypeScript 2.3 (2017), TypeScript 2.2 (2017), TypeScript 2.1 (2016), TypeScript 2.0 (2016), TypeScript 1.8 (2016), TypeScript 1.7 (2015), TypeScript 1.6 (2015), TypeScript 1.5 (2015), TypeScript 1.4 (2015), TypeScript 1.3 (2014), TypeScript 1.1 (2013), TypeScript 1.0 (2012). (navbar_typecript_versions - see also navbar_typescript, navbar_javacript_versions

TypeScript: TypeScript Glossary, TypeScript Best Practices, Web Development Best Practices, JavaScript Best Practices, TypeScript Fundamentals, TypeScript Inventor - TypeScript Language Designer: Anders Hejlsberg of Microsoft on October 1, 2012; TypeScript Keywords, TypeScript Built-In Data Types, TypeScript Data Structures - TypeScript Algorithms, TypeScript Syntax, TypeScript on Linux, TypeScript on macOS, TypeScript on Windows, TypeScript on Android, TypeScript on iOS, TypeScript Installation, TypeScript Containerization (TypeScript with Docker, TypeScript with Podman, TypeScript and Kubernetes), TypeScript OOP - TypeScript Design Patterns, Clean TypeScript - TypeScript Style Guide, TypeScript Best Practices - TypeScript BDD, Web Browser, Web Development, HTML-CSS, TypeScript Frameworks (Angular), JavaScript Libraries (React.js with TypeScript, Vue.js with TypeScript, jQuery with TypeScript), TypeScript on the Server (TypeScript with Node.js, TypeScript with Deno, TypeScript with Express.js), TypeScript Compiler (tsc, tsconfig.json), TypeScript Transpiler (Transpile TypeScript into JavaScript), Babel and TypeScript, TypeScript Package Management, NPM and TypeScript, NVM and TypeScript, Yarn Package Manager and TypeScript, TypeScript IDEs (Visual Studio Code, Visual Studio, JetBrains WebStorm), TypeScript Development Tools, TypeScript Linter, TypeScript Debugging (Chrome DevTools, JavaScript Source Maps), TypeScript Testing (TypeScript TDD, Selenium, Jest, Mocha.js, Jasmine, Tape Testing (tap-producing test harness for Node.js and browsers), Supertest, React Testing Library, Enzyme.js React Testing, Angular TestBed), TypeScript DevOps - TypeScript SRE, TypeScript Data Science - TypeScript DataOps, TypeScript Machine Learning, TypeScript Deep Learning, Functional TypeScript, TypeScript Concurrency (WebAssembly - WASM) - TypeScript Async (TypeScript Await, TypeScript Promises, TypeScript Workers - Web Workers, Service Workers, Browser Main Thread), TypeScript Concurrency, TypeScript History, TypeScript Bibliography, Manning TypeScript Series, TypeScript Glossary, TypeScript T, TypeScript Courses, TypeScript Standard Library, TypeScript Libraries, TypeScript Frameworks (Angular), TypeScript Research, JavaScript, TypeScript GitHub, Written in TypeScript, TypeScript Popularity, TypeScript Awesome, TypeScript Versions. (navbar_typescript - see also navbar_javascript, navbar_javascript_libraries, navbar_typescript_libraries, navbar_typescript_versions, navbar_typescript_standard_library, navbar_typescript_libraries, navbar_typescript_reserved_words, navbar_typescript_functional, navbar_typescript_concurrency, navbar_typescript_async, navbar_javascript_standard_library, navbar_react.js, navbar_angular, navbar_vue, navbar_javascript_standard_library, navbar_web_development)


© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


typescript_3.7.txt · Last modified: 2024/04/28 03:13 by 127.0.0.1