DEV Community

Discussion on: TypeScript - get types from data using typeof

Collapse
 
karataev profile image
Eugene Karataev • Edited

New TS Handbook has a mention about [number] syntax:

const MyArray = [
    { name: "Alice", age: 15 },
    { name: "Bob", age: 23 },
    { name: "Eve", age: 38 }
];
type T = (typeof MyArray)[number];
Enter fullscreen mode Exit fullscreen mode