Access to static properties via this.constructor in typescript

but in typescript this.constructor.prop causes error “TS2339: Property ‘prop’ does not exist on type ‘Function’”. Typescript does not infer the type of constructor to be anything beyond Function (after all … the constructor might be a sub class). So use an assertion: class SomeClass { static prop = 123; method() { (this.constructor as typeof SomeClass).prop; … Read more

Anonymous/inline interface implementation in TypeScript

OK, I finally discovered the problem to question 2 – I was using the fat arrow => to declare the object’s method here: doThatThing(<Doable>{ private message: ‘ahoy-hoy!’, do: () => { // using fat arrow: global scope replaces new object’s scope alert(this.message); } }); …which “sucked” the global scope into the method. The problem is … Read more

How to structure utility class

If you create a file utils.ts which contains export default class Utils { static doSomething(val: string) { return val; } static doSomethingElse(val: string) { return val; } } then you can simplify your client code like this: import Utils from ‘./utils’ export class MyClass { constructor() { Utils.doSomething(“test”); } }

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