indexable types typescript code example
Example 1: typescript interface
interface LabeledValue {
label: string;
}
function printLabel(labeledObj: LabeledValue) {
console.log(labeledObj.label);
}
let myObj = { size: 10, label: "Size 10 Object" };
printLabel(myObj);Try
Example 2: indexable type in ts
//Indexable type Typescript
interface ListItem {
[prop: string ] : string | number ;
}
const List: ListItem = {
name: "joyous jackal" ;
email: "[email protected]";
age: 21 ;
}