User Tools

Site Tools


typescript_3.6

TypeScript 3.6

Return to TypeScript Version History, TypeScript, JavaScript


TypeScript 3.6, released in August 2019, introduced a set of new features and improvements that targeted better type checking, more accurate type declarations, and enhanced developer tooling experiences. This version aimed to refine the language and provide developers with tools to write safer and more predictable code. Below are the key features and enhancements of TypeScript 3.6, including code examples and comparisons to similar features in other programming languages. Additionally, links to essential TypeScript resources are provided.

- 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. Stricter Generators

TypeScript 3.6 improved the type-checking for generators, ensuring that the `yield` expressions properly match the generator's declared `yield` type, and the return type matches the `return` statement in the generator.

```typescript function* numberGenerator(): Generator<number, string, boolean> {

 const next = yield 1;
 if (next) {
   return "done";
 }
} ```

JavaScript generators provide similar runtime behavior but without static type checking. C# has iterator methods (`yield return`), which are statically typed. Java's streams and Python's generators offer similar functionality but lack TypeScript's static type enforcement.

  1. More Accurate Array Spread

TypeScript 3.6 improved the accuracy of the array spread operator (`…`), where spreading an array would account for `null` and `undefined` types, making type checks stricter and more predictable.

```typescript const arr1 = [1, 2, 3]; const arr2 = [null, …arr1, 4]; // Type is (number | null)[] ```

JavaScript supports array spreading with similar syntax but lacks type safety. C#'s LINQ and Java's Streams API provide mechanisms for combining collections that are type-safe. Python's list unpacking provides similar functionality but without static type checking.

  1. Improved UX for Promises

TypeScript 3.6 enhanced the user experience when working with Promises, particularly in `.then` method callbacks, by providing more specific types for `resolve` and `reject` parameters.

```typescript new Promise<string>1); ```

This feature mirrors the improvements seen in JavaScript ES6 with Promises but with added type safety. C#'s async/await and Java's CompletableFuture provide similar promise-like patterns with static typing. Python's asyncio library offers promise-like futures but without TypeScript's type safety.

  1. Stronger Type Checking for Bind, Call, and Apply

TypeScript 3.6 strengthened the type checking for `bind`, `call`, and `apply` methods on functions, ensuring arguments match the function's parameters more strictly.

```typescript function greet(name: string) {

 console.log(`Hello, ${name}!`);
}

const greetJane = greet.bind(null, “Jane”); greetJane(); // TypeScript checks that “Jane” is a string ```

JavaScript supports these function methods but without type checks. C# delegates and Java method references offer similar functionality with type safety. Python's `functools.partial` provides a way to pre-specify function arguments, though without static typing.

  1. Semicolon-Aware Code Edits

TypeScript 3.6 introduced semicolon-aware code edits in the TypeScript language service, reducing the likelihood of syntax errors during automatic refactoring and code fixes that involve semicolon insertion or removal.

This improvement is specific to TypeScript's tooling and does not have a direct comparison in C#, Java, or Python, although modern IDEs for these languages offer similar refactoring tools that are syntax-aware.

  1. Better Unicode Support for Identifiers

TypeScript 3.6 improved support for Unicode characters in identifiers, aligning with the ECMAScript specification and allowing for a wider range of character sets in variable names and other identifiers.

```typescript const π = Math.PI; ```

JavaScript, as of ES2015, also supports Unicode identifiers. C#, Java, and Python similarly support Unicode in identifiers, allowing for more expressive and localized variable names.

  1. JSDoc Property Modifiers

TypeScript 3.6 allowed for JSDoc property modifiers to be used in JavaScript files to specify `readonly` properties, enhancing the integration with JavaScript codebases and documentation practices.

```javascript /** @type

  • /

const obj = { prop: “value” }; ```

While JSDoc is specific to JavaScript, similar documentation-driven type specifications can be found in languages like Python with type comments (PEP 484). C# and Java use annotations and modifiers directly in code for similar purposes.

  1. Improved Error Messages

and Suggestions

TypeScript 3.6 focused on improving error messages and suggestions, making them more informative and actionable, which helps developers understand and fix type errors more efficiently.

Enhanced error messaging is a quality-of-life improvement found across many languages' compilers and IDEs, aiming to improve developer productivity and code quality.

  1. `–declarationMap` for `–build` Mode

TypeScript 3.6 added support for generating declaration source maps (`–declarationMap`) when using project references in `–build` mode, enhancing the debugging experience for developers working in codebases that compile to JavaScript.

Source maps are widely used in JavaScript tooling to improve the debugging experience. C#, Java, and Python use different mechanisms, such as PDB files and source attachments, for debugging compiled code.

  1. Conclusion

TypeScript 3.6 introduced a range of features aimed at improving the developer experience through better type safety, tooling support, and language functionality. By offering stricter type checking for common JavaScript patterns, enhanced promise handling, and improved tooling experiences, TypeScript 3.6 helps developers write more reliable and maintainable code. Comparing these features with those in languages like C#, Java, and Python highlights TypeScript's unique position in providing a statically typed experience for JavaScript developers, blending the dynamic nature of JavaScript with the safety and robustness of static typing.


1)
resolve, reject) ⇒ {
 resolve("success");
 // Parameter types are automatically inferred
}).then((result) ⇒ console.log(result
typescript_3.6.txt · Last modified: 2024/04/28 03:13 (external edit)