Typescript Types
Mapped Types
In TypeScript, you can define an object type where the keys are strings and the values are also strings using an index signature:
interface StringObject {
[key: string]: string;
}
const myObject: StringObject = {
name: "Mariappan",
city: "Tamilnadu"
};
Explanation:
[key: string]: string;: This is an index signature. It defines that any key within the object must be a string, and the corresponding value associated with that key must also be a string.StringObject: This is an interface that acts as a blueprint for the object you want to create.myObject: This is an object that conforms to theStringObjectinterface.