Is there a way to use a property/key of an interface as a function argument type?
For example, if I have an interface:
interface column{
id: string,
title: string,
description: string
}
and I have a function:
const replaceColumnProperty = (col: column, property: string, val: string) => {
col[property] = val;
}
Typescript complains that type string does not match column interface.
It should be:
const replaceColumnProperty = (col: column, property: 'id' | 'title' | 'description', val: string) => {
col[property] = val;
}
However, my interface has 20 properties. Is there a way to avoid having to write a constant for each interface property?