Questions tagged [typescript]

TypeScript is a typed superset of JavaScript that transpiles to plain JavaScript. It adds optional types, classes, interfaces, and modules to JavaScript. This tag is for questions specific to TypeScript. It is not used for general JavaScript questions.

enter image description here

TypeScript is a typed superset of that transpiles to plain JavaScript. It adds optional types, classes, interfaces, and modules to JavaScript. It was developed by Microsoft and is open source.

  • TypeScript offers classes, modules, and interfaces to help developers build robust components.
  • TypeScript types let developers define interfaces between software components and gain insight into the behaviour of existing JavaScript libraries.
  • TypeScript starts from the syntax and semantics millions of JavaScript developers know today.
  • With TypeScript, developers can use existing JavaScript code, incorporate popular JavaScript libraries, and be called from other JavaScript code.
  • TypeScript transpiles to JavaScript code which runs on any browser, in , or in any other ES3-compatible environment.
  • TypeScript as a language extension adds (amongst others) the following features:
    • Type annotations and compile-time type checking
    • Namespaces
    • Interfaces
    • Enums (to define a set of named constants)
    • Generics (classes, types, and functions that can work over a variety of types)

Useful Links


221613 questions
27 answers

Interfaces vs Types in TypeScript

What is the difference between these statements (interface vs type) in TypeScript? interface X { a: number b: string } type X = { a: number b: string };
49 answers

Can't bind to 'ngModel' since it isn't a known property of 'input'

I have this simple input in my component which uses [(ngModel)] : And I get the following error when I launch my app, even if the component is not displayed. zone.js:461 Unhandled Promise…
Anthony Brenelière
  • 60,646
  • 14
  • 46
  • 58
5 answers

What is TypeScript and why would I use it in place of JavaScript?

Can you please describe what the TypeScript language is? What can it do that JavaScript or available libraries cannot do, that would give me reason to consider it?
Mohammed Thabet
  • 21,387
  • 7
  • 27
  • 43
18 answers

How to convert a string to number in TypeScript?

Given a string representation of a number, how can I convert it to number type in TypeScript? var numberString: string = "1234"; var numberValue: number = /* what should I do with `numberString`? */;
  • 23,515
  • 9
  • 32
  • 47
48 answers

Can't bind to 'formGroup' since it isn't a known property of 'form'

The situation I am trying to make what should be a very simple form in my Angular application, but no matter what, it never works. The Angular version Angular 2.0.0 RC5 The error Can't bind to 'formGroup' since it isn't a known property of…
  • 20,760
  • 39
  • 126
  • 178
6 answers

In TypeScript, what is the ! (exclamation mark / bang) operator when dereferencing a member?

When looking at the source code for a tslint rule, I came across the following statement: if (node.parent!.kind === ts.SyntaxKind.ObjectLiteralExpression) { return; } Notice the ! operator after node.parent. Interesting! I first tried compiling…
Mike Chamberlain
  • 39,692
  • 27
  • 110
  • 158
30 answers

How do you explicitly set a new property on `window` in TypeScript?

I setup global namespaces for my objects by explicitly setting a property on window. window.MyNamespace = window.MyNamespace || {}; TypeScript underlines MyNamespace and complains that: The property 'MyNamespace' does not exist on value of type…
  • 32,695
  • 11
  • 50
  • 61
38 answers

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

I read how TypeScript module resolution works. I have the following repository: @ts-stack/di. After compiling the directory structure is as follows: ├── dist │   ├── annotations.d.ts │   ├── annotations.js │   ├── index.d.ts │   ├── index.js │   ├──…
  • 27,251
  • 11
  • 40
  • 63
12 answers

get and set in TypeScript

I'm trying to create get and set method for a property: private _name: string; Name() { get: { return this._name; } set: { this._name = ???; } } What's the keyword to set a value?
  • 15,195
  • 17
  • 54
  • 82
37 answers

Property '...' has no initializer and is not definitely assigned in the constructor

in my Angular app i have a component: import { MakeService } from './../../services/make.service'; import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-vehicle-form', templateUrl: './vehicle-form.component.html', …
Mikhail Kostiuchenko
  • 9,121
  • 4
  • 15
  • 28
29 answers

How do I dynamically assign properties to an object in TypeScript?

If I wanted to programatically assign a property to an object in Javascript, I would do it like this: var obj = {}; obj.prop = "value"; But in TypeScript, this generates an error: The property 'prop' does not exist on value of type '{}' How am I…
Peter Olson
  • 139,199
  • 49
  • 202
  • 242
9 answers

Are strongly-typed functions as parameters possible in TypeScript?

In TypeScript, I can declare a parameter of a function as a type Function. Is there a "type-safe" way of doing this that I am missing? For example, consider this: class Foo { save(callback: Function) : void { //Do the save var…
  • 138,677
  • 31
  • 291
  • 286
20 answers

What is "not assignable to parameter of type never" error in TypeScript?

Code is: const foo = (foo: string) => { const result = [] result.push(foo) } I get the following TS error: [ts] Argument of type 'string' is not assignable to parameter of type 'never'. What am I doing wrong? Is this a bug?
  • 13,856
  • 14
  • 52
  • 84
5 answers

When to use JSX.Element vs ReactNode vs ReactElement?

I am currently migrating a React application to TypeScript. So far, this works pretty well, but I have a problem with the return types of my render functions, specifically in my functional components. I have always used JSX.Element as the return…
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
20 answers

How do I remove an array item in TypeScript?

I have an array that I've created in TypeScript and it has a property that I use as a key. If I have that key, how can I remove an item from it?
Tim Almond
  • 12,088
  • 10
  • 40
  • 50
2 3
99 100