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

Videos

221613 questions
53
votes
10 answers

Angular2, HostListener, how can I target an element? can I target based on class?

In Angular2, how can I target an element within the HostListener decorator? @HostListener('dragstart', ['$event']) onDragStart(ev:Event) { console.log(ev); } @HostListener('document: dragstart', ['$event']) onDragStart(ev:Event)…
GWorking
  • 4,011
  • 10
  • 49
  • 90
53
votes
7 answers

Angular 2 declaring an array of objects

I have the following expression: public mySentences:Array = [ {id: 1, text: 'Sentence 1'}, {id: 2, text: 'Sentence 2'}, {id: 3, text: 'Sentence 3'}, {id: 4, text: 'Sentenc4 '}, ]; which is not working because my array is not…
TheUnreal
  • 23,434
  • 46
  • 157
  • 277
53
votes
6 answers

Declaring events in a TypeScript class which extends EventEmitter

I have a class extends EventEmitter that can emit event hello. How can I declare the on method with specific event name and listener signature? class MyClass extends events.EventEmitter { emitHello(name: string): void { this.emit('hello',…
aleung
  • 9,848
  • 3
  • 55
  • 69
53
votes
1 answer

interface states and props in typescript react

I'm working on a project that uses TypeScript as well as React and I am new to both. My question is about interface in TypeScript and how that relates to props and states. What is actually happening? My application doesn't run at all unless I…
ceckenrode
  • 4,543
  • 7
  • 28
  • 48
53
votes
5 answers

angular 2 access ng-content within component

How can I access the "content" of a component from within the component class itself? I would like to do something like this: my text to transform to upper case How can I get the content or the upper tag within my component like I…
Daniel Kobler
  • 533
  • 1
  • 4
  • 5
53
votes
2 answers

Angular2 *ngFor in select list, set active based on string from object

I'm trying using the ngFor on my select DropDownList. Have loaded in the options which should be in the dropdown. The code you see here:

Mikkel
  • 1,771
  • 11
  • 35
  • 59
53
votes
2 answers

Angular2 RxJS getting 'Observable_1.Observable.fromEvent is not a function' error

I'm using AngularJS 2 Beta 0 and I'm trying to create an RxJS Observable from an event on a window object. I believe I know the formula for capturing the event as an Observable in my service: var observ = Observable.fromEvent(this.windowHandle,…
Michael Oryl
  • 20,856
  • 14
  • 77
  • 117
53
votes
2 answers

What means "ambient" in TypeScript

I don't understand what means the word ambient in the following sentence: A function implementation cannot be declared in an ambient context. I'm not sure to understand the general meaning of the word, (English isn't my maternal language) and if…
Vadorequest
  • 16,593
  • 24
  • 118
  • 215
53
votes
2 answers

Passing array as arguments in TypeScript

I have two methods: static m1(...args: any[]) { //using args as array ... } static m2(str: string, ...args: any[]){ //do something //.... //call to m1 m1(args); } The call to m1(1,2,3) works as expect. However, the call…
langtu
  • 1,198
  • 1
  • 10
  • 23
52
votes
2 answers

Cannot find module 'ts-transformer-keys'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?

I want to use ts-transformer-keys in my typescript project "typescript": "^4.5.5". Then I added this dependencies in the typescript package.json: "ts-transformer-keys": "^0.4.3", and added this config in tsconfig.json like this: "plugins": [ …
Dolphin
  • 29,069
  • 61
  • 260
  • 539
52
votes
8 answers

How can I make one property non-optional in a typescript type?

I have this type: type User = { id: string; name?: string; email?: string; } And I would like to construct a similar type with name non optional: type UserWithName = { id: string; name: string; email?: string; } Instead of repeating…
Louis Coulet
  • 3,663
  • 1
  • 21
  • 39
52
votes
13 answers

Failed to load module script

After deploying an Angular app on Heroku, a blank page is shown when URL is reached and console is showing MIME type errors. error is: Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME…
HUSEN SHAIKH
  • 671
  • 1
  • 5
  • 10
52
votes
5 answers

Observable `of` deprecated. What is the equivalent?

In my case, I have an access token, and should that token exist, I would return it as an observable of type string: if (this.accessToken){ return of(this.accessToken); } Due to a recent update, I noticed that of is deprecated with the following…
user1059939
  • 1,613
  • 2
  • 20
  • 37
52
votes
5 answers

Why ESLint throws 'no-unused-vars' for TypeScript interface?

So, I have this piece of code in .ts file: import {MicroEventInterface} from '../Interfaces'; export default class MicroEvent implements MicroEventInterface { // code And ESLint throws this error: I have this config for TypeScript in…
Nikita Shchypyplov
  • 1,090
  • 1
  • 9
  • 18
52
votes
4 answers

useRef "refers to a value, but is being used as a type here."

I'm trying to figure out how to tell react which element is being used as ref i.e. in my case const circleRef = useRef(undefined); AnimatedCircle is an SVG component from a third party library, and defining it this way causes…
Ilja
  • 44,142
  • 92
  • 275
  • 498
1 2 3
99
100