Lodash'da _.map ile kullanılacak bir sözlük nasıl bildirilir?Typescript lodash: _.map ile kullanılacak bir sözlük nasıl bildirilir?
İşte örnek 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 }; });
}
Bu, question.options bildiriminden memnun değildir ve aşağıdaki hatayı verir.
"{[key: number] türünde argüman: string; ,
map<T, TResult>(
collection: Array<T>,
callback: ListIterator<T, TResult>,
thisArg?: any): TResult[];
Bir dizi için collection
değişken gerektirir:} map
yöntem DefinitelyTyped aşağıdaki gibi tanımlanmıştır