User Tools

Site Tools


typescript_3.2

TypeScript 3.2

Return to TypeScript Version History, TypeScript, JavaScript


TypeScript 3.2, released in November 2018, introduced a range of features aimed at enhancing developer experience, improving the type system, and broadening the language's capabilities. This version continued TypeScript's evolution as a powerful tool for JavaScript developers by adding stricter type-checking options, expanding the utility types, and optimizing compiler checks. Below is an overview of the main features and improvements introduced in TypeScript 3.2, along with code examples, comparisons to similar features in other programming languages, and links to essential TypeScript resources.

- 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. Strict Bind, Call, and Apply Checking

TypeScript 3.2 introduced stricter checking for the `bind`, `call`, and `apply` methods on functions, ensuring that arguments for these methods align with the original function's parameters.

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

 return `${greeting}, ${name}!`;
}

const personName = “Alice”; const boundGreet = greet.bind(undefined, personName); console.log(boundGreet(“Hello”)); // Error in TypeScript 3.2 if strict checking is enabled ```

In JavaScript, these methods do not have built-in type checks. C# and Java offer method overloading and delegate binding with compile-time type safety. Python's dynamic nature allows similar runtime binding but without static type checks.

  1. Object Spread on Generic Types

TypeScript 3.2 improved the handling of object spreads with generic types, allowing for more accurate type inference when spreading an object of a generic type into another object.

```typescript function spread<T>(obj: T) {

 return { ...obj, additionalProp: "extra" };
} ```

JavaScript supports object spread syntax but lacks type inference. C#'s anonymous types and Java's `Map` merging offer somewhat similar functionality with type safety. Python's dictionaries can be merged with the `**` operator, but without static type checking.

  1. BigInt Support

TypeScript 3.2 added support for the `BigInt` type, aligning with the ECMAScript proposal for arbitrary precision integers.

```typescript const largeNumber: bigint = BigInt(1234567890123456789012345678901234567890); ```

JavaScript introduced `BigInt` in ECMAScript 2020. C# has `BigInteger` in the `System.Numerics` namespace. Java uses `BigInteger` for arbitrary precision integers. Python's integer type naturally supports arbitrary precision.

  1. `strictPropertyInitialization` in Classes

TypeScript 3.2 introduced the `strictPropertyInitialization` flag, ensuring class properties are initialized in the constructor, improving the safety of class usage.

```typescript class User {

 name: string; // Error under `strictPropertyInitialization` if not initialized
 constructor(name: string) {
   this.name = name;
 }
} ```

JavaScript classes do not enforce property initialization. C# requires non-nullable fields to be initialized either at declaration or in the constructor. Java and Python have no compile-time enforcement for property initialization in classes, relying on runtime checks.

  1. Improved Resolution for Union Types

TypeScript 3.2 enhanced type resolution for union types, particularly in the context of function overloads, leading to more intuitive behavior when working with functions that accept union types.

```typescript declare function fn(x: string): void; declare function fn(x: number): void; declare function fn(x: string | number): void; // Improved resolution in TypeScript 3.2 ```

JavaScript does not have function overloads or a static type system. C# and Java support method overloading with static type checking. Python uses dynamic typing, with optional type hints for similar patterns.

  1. The `unknown` Type

TypeScript 3.2 introduced the `unknown` type, a type-safe counterpart to `any` that requires explicit type checking before performing operations on values.

```typescript let value: unknown; value = “Hello, TypeScript!”; if (typeof value === “string”) {

 console.log(value.toUpperCase()); // Type checking required to use string methods
} ```

JavaScript's dynamic typing system does not require such checks. C#'s `object` and Java's `Object` types serve similar purposes but with different type safety guarantees. Python's dynamic nature allows all operations without static checks, but type hints can be used for similar safety.

  1. Conclusion

TypeScript 3.2 bolstered the language's type system and developer tooling, offering features like stricter function binding checks, improved handling of generic object spreads, and the introduction of `BigInt` and `unknown` types. These enhancements reflect TypeScript's ongoing commitment to providing a robust, statically typed layer on top of

JavaScript, facilitating the development of large-scale applications with improved type safety and developer experience. Comparing these features to those in languages like C#, Java, and Python highlights TypeScript's unique position in leveraging JavaScript's flexibility while incorporating strong typing principles found in traditional object-oriented languages.


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.2.txt · Last modified: 2024/04/28 03:13 by 127.0.0.1