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
| Traffic Light | |
| Regular | |
| power outage->Power failure | |
| Green* | |
| tick->Yellow | |
| Yellow | |
| tick->Red | |
| Red | |
| tick->Green | |
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
| Timer* | |
| Idle | |
| start->Running | |
| Running | |
| stop->Idle | |
| pause->Paused | |
| tick->done? | |
| Paused | |
| start->Running | |
| stop->Idle |
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
| import * as React from "react" | |
| import { mount } from "enzyme" | |
| import StoreProvider from "./StoreProvider" | |
| import Mock = jest.Mock | |
| jest.mock( "./StoreProvider", () => ({ | |
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
Show hidden characters
| { | |
| "//1//":"This doesn't seem to be needed", | |
| "compilerOptions": { | |
| // ... your setup | |
| "typeRoots": ["./custom.d.ts"] // Aka add these types on top of the other ones | |
| } | |
| } |
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 exampleReducerAction = Waffled | Pancaked | NOT_HANDLED_IN_SWITCH_CASE | |
| function breakfastReducer( state: any, action: exampleReducerAction ): any | |
| { | |
| // Note, for some reason action.type doesn't work | |
| switch ( action.type ) { | |
| case "PancakedAction": | |
| return "Gimme!" |
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 PassThroughProps | |
| { | |
| children: ReactElement | |
| } | |
| export function PassThrough( props: PassThroughProps ) | |
| { | |
| const { children, ...propsToPass } = props | |
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 type Opaque<T, K> = K & { __TYPE__: T }; | |
| // Create a new opaque type | |
| type WaffleId = Opaque<number, "waffledId">; | |
| // This function now handles the knowledge of what a waffleId is, change will only happen there if needed | |
| function makeWaffleId( number: number ): WaffleId | |
| { | |
| // ...do stuff |
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
| https://stackoverflow.com/questions/45372227/how-to-implement-typescript-deep-partial-mapped-type-not-breaking-array-properti/49936686#49936686 | |
| export type DeepPartial<T> = { | |
| [P in keyof T]?: T[P] extends Array<infer U> | |
| ? Array<DeepPartial<U>> | |
| : T[P] extends ReadonlyArray<infer U> | |
| ? ReadonlyArray<DeepPartial<U>> | |
| : DeepPartial<T[P]> | |
| }; | |
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
| yarn add testdouble @testing-library/react jest-dom testdouble-jest jest-then enzyme enzyme-adapter-react-16 @types/enzyme @types/enzyme-adapter-react-16 -D |
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
| import { Yolo } from "./yolo" | |
| import { Loggable } from "./loggable" | |
| // Nothing in this object ? Don't care, yolo | |
| const x = Yolo<any>().whatever.i.wont.fail.lolz().im.batman() | |
| // I know it's boring but If the value exist you can still access it ;) | |
| const Y = Yolo<any>( { hello: { name: "world" } } ).hello.name // -> "world" | |
| // Also, yay typescript |