typeof const FRUITS = {
apple: 'Apple',
orange: 'Orange',
banana: 'Banana'
}
type Fruits = typeof FRUITS
type Fruits = {
apple: string;
orange: string;
banana: string;
}
const FRUITS = {
apple: 'Apple',
orange: 'Orange',
banana: 'Banana'
} as const
type Fruits = typeof FRUITS
type Fruits = {
readonly apple: "Apple";
readonly orange: "Orange";
readonly banana: "Banana";
}
type FruitKey = keyof typeof FRUITS
type FruitKey = "apple" | "orange" | "banana"
type FruitValue = typeof FRUITS[keyof typeof FRUITS]
type FruitValue = "Apple" | "Orange" | "Banana"
type FavoriteFruit = Pick<Fruits, "apple" | "orange">
type FavoriteFruit = {
readonly apple: "Apple";
readonly orange: "Orange";
}
type ExcludedFavoriteFruit = Omit<Fruits, "apple" | "orange">
type ExcludedFavoriteFruit = {
readonly banana: "Banana";
}
&
type Apple = {
apple: 'Apple'
}
type Orange = {
orange: 'Orange'
}
type Banana = {
banana: 'Banana'
}
type Fruits = Apple & Orange & Banana
const obj: Fruits = {
apple: 'Apple',
orange: 'Orange',
}
Type '{ apple: "Apple"; orange: "Orange"; }' is not assignable to type 'Fruits'.
Property 'banana' is missing in type '{ apple: "Apple"; orange: "Orange"; }' but required in type 'Banana'.(2322)