Last active
January 8, 2022 06:47
-
-
Save Neo42/875c466b1e3d867a6ec6b17794c4876e to your computer and use it in GitHub Desktop.
Mapped types are the for...in loop for types.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Fruit { | |
readonly name?: string | |
readonly color?: string | |
readonly sweetness?: number | |
} | |
type Properties<Type> = keyof Type | |
type Values<Type> = Type[Properties<Type>] | |
type FruitProperties = Properties<Fruit> | |
type FruitValues = Values<Fruit> | |
type ReadonlyObject<Type> = { | |
-readonly [property in Properties<Type>]-?: Type[property] | |
} | |
type ReadonlyFruit = ReadonlyObject<Fruit> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment