TypeScript Tutorial in Hindi #34 Index signature
Index Signature In TypeScript
What is Index Signature.
How to use it with Flexible Object Shapes.
How to use readonly key.
Interview Questions.
An index signature in TypeScript allows you to define objects with dynamic keys
while specifying the type of their values.
index-signature.ts
// type userData7Type={
// [key:string]:number|string
// }
// var userData7:userData7Type={
// mobile:9999,
// id:10,
// marks:90,
// age:40,
// semester:3,
// name:'anil'
// }
type userData7Type = {
name:string,
id:number,
mobile:number,
readonly [key: string]: number | string
}
var userData7: userData7Type = {
name: 'anil',
mobile: 9999,
id: 10,
marks:90,
age:40,
semester:3,
}
index-signature.js
"use strict";
// type userData7Type={
// [key:string]:number|string
// }
var userData7 = {
name: 'anil',
mobile: 9999,
id: 10,
marks: 90,
age: 40,
semester: 3,
};