TypeScript: ‘super’ must be called before before accessing ‘this’ in the constructor of a derived class

Another solution I eventually came up with, in addition to the ones provided by @iberbeu and @Nypan, is to add and intermediary initProps() method right before the call to scream(): class Person { public firstName: string; constructor(firstName: string, props?: any) { this.firstName = firstName; this.initProps(props); this.scream(); } protected initProps(props: any): void { } protected scream(): … Read more

TypeScript: How to define custom typings for installed npm package?

Beware, this is old question (2016) regarding managing definitions using typings which is deprecated in favor of installing them straight via npm You can add custom definitions to typings.json. For example having following folder structure: /typings /custom rx-node.d.ts /global … where rx-node.d.ts is your custom typings file. For example: declare module RxNode { export interface … Read more

Typescript 1.8 modules: import all files from folder

Both module resolution strategies that tsc provides don’t support such a behavior. What your desired import statement import * as mylib from “./source/”; is actually doing is to perform checks in this order: 1. (does package.json have a typings key? If so, import this file) 2. import * as mylib from “./source/index.ts”; 3. import * … Read more

Import module from root path in TypeScript

(Re-posting my answer to avoid puppy-socket.) Using the compilerOptions.baseUrl property I was able to do the below import. This allowed me to have a complete root-to-expected-path, which helps my code maintainance, and works in any file, independently of the current folder. The below examples will have the src folder of my project as the modules … Read more

Typescript: What is type URL?

AFAICT, URL is a typescript “built-in” feature, based on the WhatWG Url specifications. The linked to page has both rationale and examples. In short it offers a structured way of using urls while making sure that they are valid. It will throw errors when attempting to create invalid urls. Typescript has the according type-definitions set … Read more

Ionic 2 – Disabling back button for a specific view

Option 1 Hide it in the view by adding the hideBackButton attribute to the ion-navbar component <ion-navbar hideBackButton=”true”> <ion-title>Sub Page</ion-title> </ion-navbar> Option 2 Hide it from within the page class by using the .showBackButton(bool) method provided by the ViewController class import { NavController, ViewController } from ‘ionic-angular’; export class SubPage { constructor(public navCtrl: NavController, private … Read more

How can I pass the FormGroup of a parent component to its child component using the current Form API

In the parent component do this: <div [formGroup]=”form”> <div>Your parent controls here</div> <your-child-component [formGroup]=”form”></your-child-component> </div> And then in your child component you can get hold of that reference like so: export class YourChildComponent implements OnInit { public form: FormGroup; // Let Angular inject the control container constructor(private controlContainer: ControlContainer) { } ngOnInit() { // Set … Read more

‘this’ is undefined inside the foreach loop

You need to either use an arrow function: myarray.days.forEach((obj, index) => { console.log(‘before transform, this : ‘ + this); this.datePipe.transform… }); Or use the bind method: myarray.days.forEach(function(obj, index) { console.log(‘before transform, this : ‘ + this); this.datePipe.transform… }.bind(this)); The reason is that when passing a regular function as a callback, when it is invoked the … Read more

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