String Union to string Array

Answer for TypeScript 3.4 and above It is not really possible to convert a union to a tuple in TypeScript, at least not in a way that behaves well. Unions are intended to be unordered, and tuples are inherently ordered, so even if you can manage to do it, the resulting tuples can behave in … Read more

‘unknown’ vs. ‘any’

You can read more about unknown in the PR or the RC announcement, but the gist of it is: [..] unknown which is the type-safe counterpart of any. Anything is assignable to unknown, but unknown isn’t assignable to anything but itself and any without a type assertion or a control flow based narrowing. Likewise, no … Read more

Could not find a declaration file for module ‘module-name’. ‘/path/to/module-name.js’ implicitly has an ‘any’ type

Here are two other solutions When a module is not yours – try to install types from @types: npm install -D @types/module-name If the above install errors – try changing import statements to require: // import * as yourModuleName from ‘module-name’; const yourModuleName = require(‘module-name’);

How to fix TS2322: “could be instantiated with a different subtype of constraint ‘object'”?

Complementing @fetzz great answer. SHORT ANSWER TLDR; There are two common causes for this kind of error message. You are doing the first one (see below). Along with the text, I explain in rich detail what this error message wants to convey. CAUSE 1: In typescript, a concrete instance is not allowed to be assigned … Read more

Expression ___ has changed after it was checked

As stated by drewmoore, the proper solution in this case is to manually trigger change detection for the current component. This is done using the detectChanges() method of the ChangeDetectorRef object (imported from angular2/core), or its markForCheck() method, which also makes any parent components update. Relevant example: import { Component, ChangeDetectorRef, AfterViewInit } from ‘angular2/core’ … Read more