How to implement class constants?

TypeScript 2.0 has the readonly modifier: class MyClass { readonly myReadOnlyProperty = 1; myMethod() { console.log(this.myReadOnlyProperty); this.myReadOnlyProperty = 5; // error, readonly } } new MyClass().myReadOnlyProperty = 5; // error, readonly It’s not exactly a constant because it allows assignment in the constructor, but that’s most likely not a big deal. Alternative Solution An alternative … Read more

About “*.d.ts” in TypeScript

The “d.ts” file is used to provide typescript type information about an API that’s written in JavaScript. The idea is that you’re using something like jQuery or underscore, an existing javascript library. You want to consume those from your typescript code. Rather than rewriting jquery or underscore or whatever in typescript, you can instead write … Read more

Could not find a declaration file for module ‘module-name’. ‘/path/to/module-name.js’ implicitly has an ‘any’ type

Here are two other solutions When a module is not yours – try to install types from @types: npm install -D @types/module-name If the above install errors – try changing import statements to require: // import * as yourModuleName from ‘module-name’; const yourModuleName = require(‘module-name’);

get and set in TypeScript

TypeScript uses getter/setter syntax that is like ECMAScript4/ActionScript3. class foo { private _bar: boolean = false; get bar(): boolean { return this._bar; } set bar(value: boolean) { this._bar = value; } } That will produce this JavaScript, using the ECMAScript 5 Object.defineProperty() feature. var foo = (function () { function foo() { this._bar = false; … Read more

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