Hi, I'm Jacob. Enjoying devFlipCards? Buy me a coffee

13. What are mapped types in TypeScript, and how are they used?

Mapped types in TypeScript are a way to create new types based on existing ones. They allow modifying the properties of objects or other types according to specific rules. Example of using mapped types:

type Person = { name: string, age: number, address: string }; type ReadOnlyPerson = { readonly [K in keyof Person]: Person[K] }; // ReadOnlyPerson will have all properties of 'Person', but they will be readonly.

Mapped types are useful when we need to generate different variations of a type based on a base type, such as creating different versions of objects or states.

Struggling to find common date to meet with your friends? Try our new tool
commondate.xyz