What return type should be used for setTimeout in TypeScript?

Simplest solution is to allow type inference to work and not specify any type at all. If you need to specify a type, seeing as the type is not consistent between the browser and node declarations, you could use ReturnType to specify that the type of the variable is whatever the return type of setTimeout is: Alternately, window.setTimeout can also be … Read more

‘tsc command not found’ in compiling typescript

A few tips in order restart the terminal restart the machine reinstall nodejs + then run npm install typescript -g If it still doesn’t work run npm config get prefix to see where npm install -g is putting files (append bin to the output) and make sure that they are in the path (the node js setup does this. Maybe … Read more

Why do i need `typings.json` file in an Angular 2 project?

So, I’ve found this: Any JavaScript libraries, such as jQuery, the Jasmine testing library, and Angular, extend the JavaScript environment with features and syntax that the TypeScript compiler doesn’t recognize natively. When the compiler doesn’t recognize something, it throws an error. So, If we wrote a library which may use by other persons in their … Read more

Typescript: Index signature is missing in type

The problem is that when the type is inferred, then the type of o is: That’s not the same as { dic: { [name: string]: number } }. Critically, with the top signature you’re not allowed to do something like o.dic[‘x’] = 1. With the 2nd signature you are. They are equivalent types at runtime (indeed, they’re the exact … Read more

cannot redeclare block scoped variable (typescript)

The solution for me was to convert my code from using CommonJS (require, module.exports, etc) to ES Modules (import, export, etc.) The TypeScript documentation also appears to recommend ES Module syntax: TypeScript Modules Of course there’s a lot more to it than this, but as a start: Replace instances of require with import, e.g. Replace: … Read more

Can’t bind to ‘routerLink’ since it isn’t a known property

You need to add RouterModule to imports of every @NgModule() where components use any component or directive from (in this case routerLink and <router-outlet>. declarations: [] is to make components, directives, pipes, known inside the current module. exports: [] is to make components, directives, pipes, available to importing modules. What is added to declarations only … Read more