My current challenge involves creating a "FormField" generic type that will only accept a tuple of properties' names/values from a specified type, along with additional properties like "checked".
For instance:
const formProperties: FormField<User> = [{name: "name", value: "Toto", checked: false}, {name: "age", value: 30, checked: true}]` with User defined as `interface User { name: string; age: number;}` or `const formProperties: FormField<House> = [{name: "width", value: 100, checked: true}, {name: "height", value: 50, checked: false}]` with House defined as: `interface House { width: number; height: number; }
I am aware that I could simply use:
{name: string; value: string | number | CustomType }[]
but that approach limits the ability to determine the type of "value".
Attempts with mapped types have not yielded success either.
type FormField<T> = {[Property in keyof T]: T[Property]};