Dev Helpers
← Back

Check a typed form field

Check a typed form field using TypeScript.

Open this example in the interactive library

Source code

type Fields = { name: string; age: number; subscribed: boolean };
const initial: Fields = { name: "Ada", age: 30, subscribed: false };
console.log(((field: keyof Fields) => initial[field])("name"));

Sample output

Ada