Questions tagged [typescript2.0]

Tag for questions specific to new features in TypeScript 2.x. For general TypeScript questions, the correct tag is TypeScript.

Tag for questions specific to new features in TypeScript 2.x. For general TypeScript questions, the correct tag is .

TypeScript 2.0 documentation

1412 questions
287
votes
15 answers

TypeScript and React - children type?

I have a very simple functional component as follows: import * as React from 'react'; export interface AuxProps { children: React.ReactNode } const aux = (props: AuxProps) => props.children; export default aux; And another…
Asool
  • 7,423
  • 4
  • 25
  • 41
280
votes
2 answers

What is the Record type in typescript?

What does Record mean in Typescript? Typescript 2.1 introduced the Record type, describing it in an example: // For every properties K of type T, transform it to U function mapObject(obj: Record, f: (x: T) => U):…
Matthias
  • 8,845
  • 7
  • 33
  • 52
164
votes
2 answers

'this' implicitly has type 'any' because it does not have a type annotation

When I enable noImplicitThis in tsconfig.json, I get this error for the following code: 'this' implicitly has type 'any' because it does not have a type annotation. class Foo implements EventEmitter { on(name: string, fn: Function) { } …
tony19
  • 64,135
  • 13
  • 95
  • 146
127
votes
5 answers

Purpose of declare keyword in TypeScript

What is the purpose of the declare keyword? type Callback = (err: Error | String, data: Array) => void; vs. declare type Callback = (err: Error | String, data:Array) => void; Cannot find docs that explain the…
Alexander Mills
  • 1
  • 80
  • 344
  • 642
97
votes
21 answers

Typescript error "Cannot write file ... because it would overwrite input file."

In my Typescript 2.2.1 project in Visual Studio 2015 Update 3, I am getting hundreds of errors in the error list like: Cannot write file 'C:/{{my-project}}/node_modules/buffer-shims/index.js' because it would overwrite input file. It looks like…
CBarr
  • 21,475
  • 18
  • 85
  • 119
97
votes
1 answer

How to configure custom global interfaces (.d.ts files) for TypeScript?

I'm currently working on a ReactJS project which uses Webpack2 and TypeScript. Everything works perfectly apart from one thing - I can't a find a way to move interfaces that I've written myself into separate files so that they are visible to the…
Andris
  • 4,543
  • 2
  • 24
  • 34
80
votes
2 answers

Typescript cannot find name window or document

For either case: document.getElementById('body'); // or window.document.getElementById('body'); I get error TS2304: Cannot find name 'window'. Am I missing something in tsconfig.json for a definition file I should install? I get the message when…
Steven Bayer
  • 1,377
  • 2
  • 11
  • 16
77
votes
7 answers

How to prevent "Property '...' does not exist on type 'Global'" with jsdom and typescript?

I try to convert an existing project to use Typescript and I have problems doing so with my testing setup. I had a setup file for my tests that sets up jsdom so that all my DOM interacting code works during my tests. Using Typescript (ts-node with…
fahrradflucht
  • 1,233
  • 1
  • 11
  • 20
73
votes
2 answers

TypeScript Import Path Alias

I am currently working on a TypeScript application which is comprised of multiple Node modules written in TypeScript, that are installed into the node_modules directory. Before continuing, I would like to note that I am using TypeScript 2.0, I am…
Dwayne Charrington
  • 5,822
  • 7
  • 38
  • 62
71
votes
17 answers

'ts-node' is not recognized as an internal or external command, operable program or batch file

I'm getting error in my Vs Code terminal and command prompt that 'ts-node' is not recognized as an internal or external command, operable program or batch file. while i'm trying the start command in the terminal npm run dev and i have added my…
Mugesh
  • 723
  • 1
  • 5
  • 4
69
votes
6 answers

Angular 4.3.3 HttpClient : How get value from the header of a response?

( Editor: VS Code; Typescript: 2.2.1 ) The purpose is to get the headers of the response of the request Assume a POST request with HttpClient in a Service import { Injectable } from "@angular/core"; import { HttpClient, HttpHeaders, }…
SolidCanary
  • 993
  • 1
  • 7
  • 15
66
votes
1 answer

How to add custom "typings" in typescript 2.0 / 3.0

According to this article typings system for typescript 2.0 has changed and so it is not clear how to attach custom typings now. Should I always create NPM package for that? Thank you in advance!
Lu4
  • 13,853
  • 12
  • 68
  • 122
61
votes
3 answers

Typescript 2.0. "types" field in tsconfig.json

I do not understand the meaning of types field in tsconfig.json. In documentation I have read such text: "types": { "description": "Type declaration files to be included in compilation. Requires TypeScript version 2.0 or later.", "type":…
Stalso
  • 1,230
  • 2
  • 11
  • 19
57
votes
1 answer

Usage of the TypeScript compiler argument 'skipLibCheck'

I've been researching around for a further explanation into the skipLibCheck TypeScript compiler argument to determine the safety of having this set to true. The most in-depth explanation I found is the following: New --skipLibCheck TypeScript…
Daniel Lowman
  • 582
  • 1
  • 4
  • 11
55
votes
3 answers

TypeScript custom declaration files for untyped npm modules

I am consuming a React component called shiitake from npm into my project where I use TypeScript. That library does not have TypeScript declarations so I thought I would write one. The declaration file looks like below (it may not be complete but…
tugberk
  • 54,046
  • 58
  • 232
  • 321
1
2 3
94 95