This file contains hidden or 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
| fillNames :: String -> String -> String -> String | |
| fillNames firstN middleN lastN = firstN ++ middleN ++ lastN | |
| a :: String -> String -> String | |
| a = fillNames "Jihad" | |
| b :: String | |
| b = a " Dzikri" " Waspada" | |
| b == "Jihad Dzikri Waspada" -- True |
This file contains hidden or 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
| type Tree<A> = Leaf<A> | Branch<A>; | |
| type Leaf<A> = { _f: 'tree', kind: 'leaf', value: A }; | |
| type Branch<A> = { _f: 'tree', kind: 'branch', left: Tree<A>, right: Tree<A> }; | |
| function mapTree<A, B>(map: (val: A) => B, tree: Tree<A>): Tree<B> { | |
| switch (tree.kind) { | |
| case 'leaf': | |
| return leaf(map(tree.value)); | |
| case 'branch': | |
| return branch( |
This file contains hidden or 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
| export interface TimeSlot { | |
| deliveryId: number; | |
| from: string; | |
| to: string; | |
| } | |
| export interface DeliveryTimeResponse { | |
| date: string; | |
| slots: { | |
| DayTime: TimeSlot; |
This file contains hidden or 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
| /* Enum */ | |
| enum Status { | |
| Initial, | |
| Fetching, | |
| Done, | |
| Error | |
| } | |
| interface ProductStore { | |
| products: ProductModel[]; |
This file contains hidden or 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
| /* Intersection type */ | |
| interface Goku { | |
| withKamehameha: boolean; | |
| } | |
| interface Bejita { | |
| sayKakarot: boolean; | |
| } | |
| type Gogeta = Goku & Bejita; | |
| const gogeta: Gogeta = { |
This file contains hidden or 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
| const getFinalPrice = (product: ProductModel) => | |
| product.price + product.tax; | |
| const getProductById = (products: ProductModel[], id: number) => | |
| products.find(product => product.id === id); | |
| const product = getProductById(productList, 1); | |
| const finalPrice = getFinalPrice(product); // <- ERROR | |
| // Argument of type 'ProductModel | undefined' is not assignable to parameter of type 'ProductModel'. | |
| // Type 'undefined' is not assignable to type 'ProductModel'. |
This file contains hidden or 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 ProductModel { | |
| id: number; | |
| name: string; | |
| price: number; | |
| tax: number | |
| } | |
| const productList: ProductModel[] = [ | |
| { id: 100, name: 'deluxe', price: 28, tax: 2.5 }, | |
| { id: 101, name: 'giftcard', price: 30, tax: 3 }, |
This file contains hidden or 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 ProductModel { | |
| id: number; | |
| name: string; | |
| price: number; | |
| tax: number | |
| } | |
| const getFinalPrice = (product: ProductModel) => | |
| product.price + product.tax; |
This file contains hidden or 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
| declare const _phantom: unique symbol; | |
| export type NewType<Name, Type> = Type & { [_phantom]?: Name }; | |
| export type Celcius = NewType<'Celcius', number>; | |
| export type Fahrenheit = NewType<'Fahrenheit', number>; | |
| // ...etc |
This file contains hidden or 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
| type Brand<Name, Type> = Type & { _brand?: Name } // optional | |
| type Celcius = Brand<'Celcius', number>; | |
| type Fahrenheit = Brand<'Fahrenheit', number>; | |
| const fiveC: Celcius = 5; // typechecked :) |