TypeScript 2.4 weak type detection

Click for: original source

Marius Schulz short into into TypesScript weak type detection with code examples. A type is considered weak if all of its properties are optional. More specifically, a weak type defines one or more optional properties, no required properties, and no index signatures.

The main goal of weak type detection is to find likely errors in your code that would otherwise be silent bugs. Starting with TypeScript 2.4, it’s now an error to assign anything to a weak type when there’s no overlap in properties.

Another benefit is that the TypeScript language service can give us auto completion suggestions because the type annotation tells it what type of object we’re creating.

Author then describes:

  • Workarounds for weak types
  • The Limits of weak type detection

The article is part of “TypeScript Evolution” series of blog posts with 27 parts so far. Author also provides TypeScript course where you can enhance your knowledge more.

[Read More]

Tags nodejs javascript