How to declare a dictionary for use with _.map in lodash?
Here is an example TypeScript program.
<reference path="../scripts/typings/lodash/lodash.d.ts" /> interface IQuestionAndOptions { text: string; options: { [key: number]: string }; } function sample() { var question: IQuestionAndOptions = { text: "Are you happy?", options: {} }; question['1'] = "Yes"; question['2'] = "No"; var values = _.map(question.options, function (v: string, k: number) { return { text: v, value: k }; }); }
Unhappy with the question.options declaration and gives the following error.
An argument of type '{[key: number]: string; } 'is not assigned to the parameter of the "List" type in the _.map command
source share