In Typescript, I have a function:-
function updateSetting(settingName, settingValue: string[]| number | null) {
this.props.updateSetting({[settingName]}: settingValue)
}
and i also have a object, so i have an interface for it
interface Setting {
names: string[]
city: string | null
age: number
}
So, i want to use object as an argument, and i also want that one of the property of the object is passed as an argument which is decided at the run time. So in my function settingName can be either 'name' or 'city' or 'age', so i want to assign the type from the interface itself.
I don't want to write (settingValue: string[]| number | null) i want to write something like
settingValue: valueof Setting
because setting value can be any of the type names, city, age.
How can i achieve this in typescript ?
keyof: typescriptlang.org/docs/handbook/release-notes/…. It looks like it could fit your use case