Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (29 sloc) 602 Bytes
enum PizzaType {
'hawaii',
'salami'
}
type Pizza = {
pizzaType: PizzaType;
delimiter: number
};
type MarketProduct = {
price: number;
name: string;
};
type Cake = {
flavour: 'sweet' | 'more sweet',
calories: number
};
type ProductType = 'cake' | 'pizza';
type Foo<T> = T extends 'pizza' ? Pizza :
T extends 'cake' ? Cake :
{ extra: number };
function handlePizza<T>(argument: Foo<'pizza'>) {
argument.pizzaType
}
function handleCake(argument: Foo<'cake'>) {
argument.flavour
}
function handleExtra(argument: Foo<{}>) {
argument.extra
}
You can’t perform that action at this time.