Is key-value pair available in Typescript?

Is key-value pair available in Typescript? Yes. Called an index signature: interface Foo { [key: string]: number; } let foo:Foo = {}; foo[‘hello’] = 123; foo = { ‘leet’: 1337 }; console.log(foo[‘leet’]); // 1337 Here keys are string and values are number. More You can use an es6 Map for proper dictionaries, polyfilled by core-js.

Array VS Type[] in Typescript

There isn’t any semantic difference There is no difference at all. Type[] is the shorthand syntax for an array of Type. Array<Type> is the generic syntax. They are completely equivalent. The handbook provides an example here. It is equivalent to write: function loggingIdentity<T>(arg: T[]): T[] { console.log(arg.length); return arg; } Or: function loggingIdentity<T>(arg: Array<T>): Array<T> … Read more

How to use paths in tsconfig.json?

This can be set up on your tsconfig.json file, as it is a TS feature. You can do like this: “compilerOptions”: { “baseUrl”: “src”, // This must be specified if “paths” is. … “paths”: { “@app/*”: [“app/*”], “@config/*”: [“app/_config/*”], “@environment/*”: [“environments/*”], “@shared/*”: [“app/_shared/*”], “@helpers/*”: [“helpers/*”] }, … Have in mind that the path where you … Read more

Create an enum with string values

TypeScript 2.4 Now has string enums so your code just works: enum E { hello = “hello”, world = “world” }; 🌹 TypeScript 1.8 Since TypeScript 1.8 you can use string literal types to provide a reliable and safe experience for named string values (which is partially what enums are used for). type Options = … Read more

Understanding esModuleInterop in tsconfig file

Problem statement Problem occurs when we want to import CommonJS module into ES6 module codebase. Before these flags we had to import CommonJS modules with star (* as something) import: // node_modules/moment/index.js exports = moment // index.ts file in our app import * as moment from ‘moment’ moment(); // not compliant with es6 module spec … Read more

Hide .js.map files in Visual Studio Code: File Nesting

In your settings (either user or workspace) there is a setting that you can tweak to hide anything you’d like: { “files.exclude”: { “**/.git”: true, “**/.DS_Store”: true } } So you can add in the following to hide .js and .js.map files “**/*.js”: true, “**/*.js.map”: true As this other answer explains, most people probably only … Read more

TypeScript and field initializers

Updated 07/12/2016: Typescript 2.1 introduces Mapped Types and provides Partial<T>, which allows you to do this…. class Person { public name: string = “default” public address: string = “default” public age: number = 0; public constructor(init?:Partial<Person>) { Object.assign(this, init); } } let persons = [ new Person(), new Person({}), new Person({name:”John”}), new Person({address:”Earth”}), new Person({age:20, … Read more

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