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 function convertCtoF(degree: Celcius): Fahrenheit; | |
| declare const fiveC: Celcius; | |
| declare const fiveF: Fahrenheit; | |
| convertCtoF(fiveF); // error :) | |
| // Argument of type 'Brand<"Fahrenheit", number>' is not assignable to parameter of type 'Brand<"Celcius", number>'. | |
| // Type 'Brand<"Fahrenheit", number>' is not assignable to type '{ _brand: "Celcius"; }'. | |
| // Types of property '_brand' are incompatible. | |
| // Type '"Fahrenheit"' is not assignable to type '"Celcius"'. |
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 }; | |
| type Celcius = Brand<'Celcius', number>; | |
| type Fahrenheit = Brand<'Fahrenheit', number>; |
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
| class A {} | |
| class B {} | |
| declare function onlyAcceptA(a: A): any; | |
| declare const b: B; | |
| onlyAcceptA(b); // typechecked :( |
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
| class Temp<A> { | |
| private readonly __unit__: A; | |
| constructor(degree: number) { } | |
| } | |
| enum Unit { Celcius, Fahrenheit } | |
| const isBoiling = (temp: Temp<Unit.Celcius>) => temp.degree >= 100; | |
| const c100 = new Temp<Unit.Celcius>(100); |
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
| class FormData<T> { | |
| private readonly __data__: T; | |
| constructor(value: any) { } | |
| } | |
| interface Unvalidated { __unval__: never } | |
| interface Validated { __val__: never } | |
| declare function validate(data: FormData<Unvalidated>): FormData<Validated>; | |
| declare function sendToBackend(payload: FormData<Validated>): Promise<any> |
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
| class Temp<A> { | |
| private readonly __unit__: A; // structural diff used here | |
| constructor(degree: number) { } | |
| } | |
| interface Celcius { __celcius__: never } // structural diff | |
| interface Fahrenheit { __fahrenheit__: never } // structural diff | |
| const isBoiling = (temp: Temp<Celcius>) => temp.degree >= 100; |
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
| class Temp<A> { | |
| constructor(degree: number) { } | |
| } | |
| interface Celcius {} | |
| interface Fahrenheit {} | |
| declare function isBoiling(temp: Temp<Celcius>): boolean; |
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 accRepo: AccountRepo = { | |
| find: no => ({ name: 'Bambang', email: 'tampan@tampan.com' }) | |
| }; | |
| declare function debit(no: string, amount: number): () => Reader<AccountRepo, Account>; | |
| declare function credit(no: string, amount: number): () => Reader<AccountRepo, Account>; | |
| declare function balance(no: string): () => Reader<AccountRepo, number>; | |
| const transaksiBambangF = (no: string) => composeK( | |
| balance(no), // <- Cleaner |
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 const AsyncState = { // <- HERE | |
| initial: 'initial', | |
| fetching: 'fetching', | |
| success: 'success', | |
| error: 'error' | |
| } | |
| const initialState = { | |
| asyncState: AsyncState.initial, | |
| }; |
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 initialState = { ... }; | |
| export default (state = initialState, action) => { | |
| switch(action.type) { | |
| case 'GET_XXX_REQUEST': | |
| return { | |
| ...state, | |
| isLoading: true, isLoaded: false, error: null // <- Here | |
| } | |
| case 'GET_XXX_SUCCESS': |