Is key-value pair available in Typescript?

CodeHunter picture CodeHunter · Apr 7, 2016 · Viewed 207.7k times · Source

Is key,value pair available in typescript? If yes how to do that. Can anyone provide sample example links.

Answer

basarat picture basarat · Apr 7, 2016

Is key-value pair available in Typescript?

Yes. Called an index signature:

interface Foo {
   [key: string]: Bar;
} 
let foo:Foo = {};

Here keys are string and values are Bar.

More

You can use an es6 Map for proper dictionaries, polyfilled by core-js.