Why is Event.target not Element in Typescript?

I simply want to do this with my KeyboardEvent var tag = evt.target.tagName.toLowerCase(); While Event.target is of type EventTarget, it does not inherit from Element. So I have to cast it like this: var tag = (<Element>evt.target).tagName.toLowerCase(); This is probably due to some browsers not following standards, right? What is the correct browser-agnostic implementation in … Read more

Angular 4 HttpClient Query Parameters

I have been looking for a way to pass query parameters into an API call with the new HttpClientModule‘s HttpClient and have yet to find a solution. With the old Http module you would write something like this. getNamespaceLogs(logNamespace) { // Setup log namespace query parameter let params = new URLSearchParams(); params.set(‘logNamespace’, logNamespace); this._Http.get(`${API_URL}/api/v1/data/logs`, { … Read more

How to extend / inherit components?

I would like to create extensions for some components already deployed in Angular 2, without having to rewrite them almost completely, as the base component could undergo changes and wish these changes were also reflected in its derived components. I created this simple example to try to explain better my questions: With the following base … Read more

How to declare a Fixed length Array in TypeScript

At the risk of demonstrating my lack of knowledge surrounding TypeScript types – I have the following question. When you make a type declaration for an array like this… position: Array<number>; …it will let you make an array with arbitrary length. However, if you want an array containing numbers with a specific length i.e. 3 … Read more

Error: ‘types’ can only be used in a .ts file – Visual Studio Code using @ts-check

I am starting to use TypeScript in a Node project I am working on in Visual Studio Code. I wanted to follow the “opt-in” strategy, similar to Flow. Therefore I put // @ts-check at the top of my .js file in hope to enable TS for that file. Ultimately I want the same experience of … Read more

How to use a typescript enum value in an Angular2 ngSwitch statement

The Typescript enum seems a natural match with Angular2’s ngSwitch directive. But when I try to use an enum in my component’s template, I get “Cannot read property ‘xxx’ of undefined in …”. How can I use enum values in my component template? Please note that this is different from how to create html select … Read more

Angular 2 ‘component’ is not a known element

I’m trying to use a component I created inside the AppModule in other modules. I get the following error though: “Uncaught (in promise): Error: Template parse errors: ‘contacts-box’ is not a known element: If ‘contacts-box’ is an Angular component, then verify that it is part of this module. If ‘contacts-box’ is a Web Component then … Read more