Why is ES7/array polyfill needed despite the tsconfig target is set to ES5

TypeScript does not auto-polyfill code (see microsoft/TypeScript#3101). The “official” reason from the relevant GitHub issue seems to be, as @RyanCavanaugh said: Having the compiler try to figure out which [ES20XX] methods you need, and where to emit them, and when, with controls for people who don’t want the polyfills emitted, and ways to change where … Read more

How to consume npm modules from typescript?

[2018/12] New, up-to-date, answer to this question I asked in 2016, which stills shows a lot of activity despite having outdated answers. Long story short, TypeScript requires type informations about your package’s code (a.k.a. “type declaration files” a.k.a. “typings”) and rightfully tells you that you would otherwise be losing the whole point of TypeScript. There … Read more

Typescript primitive types: any difference between the types “number” and “Number” (is TSC case-insensitive)?

To augment Ryan’s answer with guidance from the TypeScript Do’s and Don’ts: Don’t ever use the types Number, String, Boolean, Symbol, or Object These types refer to non-primitive boxed objects that are almost never used appropriately in JavaScript code. /* WRONG */ function reverse(s: String): String; Do use the types number, string, boolean, and symbol. … Read more

How do you produce a .d.ts “typings” definition file from an existing JavaScript library?

There are a few options available for you depending on the library in question, how it’s written, and what level of accuracy you’re looking for. Let’s review the options, in roughly descending order of desirability. Maybe It Exists Already Always check DefinitelyTyped (https://github.com/DefinitelyTyped/DefinitelyTyped) first. This is a community repo full of literally thousands of .d.ts … Read more