На примере будет более понятно:
type Obj = {
field1: string;
field2: number;
};
const obj1: Obj = { field1: 'obj1', field2: 1 };
const obj2: Obj = { field1: 'obj2', field2: 2 };
const objList = [obj1, obj2]
const getObjSetter = (index: number, fieldName: keyof Obj) => (value: ???) => {
const obj = objList[index];
obj[field] = value
return obj
}
http://www.typescriptlang.org/play/#code/C4TwDgpgBA8gRgKygXigbwFBW1AZgSwgBsATARgC4oBnYAJ3wDsBzAbixwOJICYrGArgFs4EOuwC+7DAGMA9o1pQ5iSrEQp0eQqTUByFQjJ6ANNu58oZKFNkKlhy-CSo053VQOIep97yo8NuzyisDKiAAy+EqoANqGZGaOALoYdqFQzBDAzgDK2cBimgA8ANIQIFAQAB6FjCTUUADWFXK46ggAfAAUTCQ1-MKidGZcpAByAIZCEFTlIACUKJ1Q3QBuk0QCsx2x88lLyCuYOFAhDhqohlG0sX01yeynhrFjJFMzyZobWxDSp3RsgI6IxwghJBggA
Обсуждают сегодня