Why is Event.target not Element in Typescript?

It doesn’t inherit from Element because not all event targets are elements. From MDN: Element, document, and window are the most common event targets, but other objects can be event targets too, for example XMLHttpRequest, AudioNode, AudioContext, and others. Even the KeyboardEvent you’re trying to use can occur on a DOM element or on the … Read more

Angular 2 Show and Hide an element

There are two options depending what you want to achieve : You can use the hidden directive to show or hide an element <div [hidden]=”!edited” class=”alert alert-success box-msg” role=”alert”> <strong>List Saved!</strong> Your changes has been saved. </div> You can use the ngIf control directive to add or remove the element. This is different of the … Read more

How to declare a Fixed length Array in TypeScript

The JavaScript array has a constructor that accepts the length of the array: let arr = new Array<number>(3); console.log(arr); // [undefined × 3] However, this is just the initial size, there’s no restriction on changing that: arr.push(5); console.log(arr); // [undefined × 3, 5] TypeScript has tuple types which let you define an array with a … Read more

How can I define an interface for an array of objects?

You don’t need to use an indexer (since it a bit less typesafe). You have two options : interface EnumServiceItem { id: number; label: string; key: any } interface EnumServiceItems extends Array<EnumServiceItem>{} // Option A var result: EnumServiceItem[] = [ { id: 0, label: ‘CId’, key: ‘contentId’ }, { id: 1, label: ‘Modified By’, key: … Read more

How do you produce a .d.ts “typings” definition file from an existing JavaScript library?

There are a few options available for you depending on the library in question, how it’s written, and what level of accuracy you’re looking for. Let’s review the options, in roughly descending order of desirability. Maybe It Exists Already Always check DefinitelyTyped (https://github.com/DefinitelyTyped/DefinitelyTyped) first. This is a community repo full of literally thousands of .d.ts … Read more

TypeScript sorting an array

Numbers When sorting numbers, you can use the compact comparison: var numericArray: number[] = [2, 3, 4, 1, 5, 8, 11]; var sortedArray: number[] = numericArray.sort((n1,n2) => n1 – n2); i.e. – rather than <. Other Types If you are comparing anything else, you’ll need to convert the comparison into a number. var stringArray: string[] … Read more

public static const in TypeScript

If you did want something that behaved more like a static constant value in modern browsers (in that it can’t be changed by other code), you could add a get only accessor to the Library class (this will only work for ES5+ browsers and NodeJS): export class Library { public static get BOOK_SHELF_NONE():string { return … Read more

What’s the difference between ‘extends’ and ‘implements’ in TypeScript

Short version extends means: The new class is a child. It gets benefits coming with inheritance. It has all the properties and methods of its parent. It can override some of these and implement new ones, but the parent stuff is already included. implements means: The new class can be treated as the same “shape”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)