-
Mise-en-place sets your stage for a delightful code cooking
tool
I am slow in the hype-cycle. Devenv.sh for years was my loyal environment manager and, with all it quirks in fish shell in particular, was good enough. One day in which I could’t get SecretSpec to work I found out about Mise which its rich ecosystem. Granted there is much more magic involved then in Devenv.sh but features, speed and reliability is unmatched in any way. Give it try you even can pull packages from nixpkgs which was the last straw keeping me in devenv.sh.~ 90 words -
I only recently discovered nix-community/comma but can’t stop praising it for its utility. Need a tool - comma has it! Need ponysay, but don’t want to nix-rebuild or forgot how to type nix run again. How about running:
, ponysay "its that easy?"Works with sudo and even shell piping
~ 48 words -
Utility: Flatten nested types
typescriptThis mapped type is a ‘noop type’ in the sense that
input type === output type. Still, but comes in handy with intersection/composed types when editing code as it flattens the given input type. As an example,type Ugly = {id: string;} & {date: Date;} // becomes type Pretty = {id: string; date: Date;} // with type Flatten<T> = { [K in keyof T]: T[K]; } & {};~ 65 words -
This structure guarantees to return a string. It’s super useful for all kinds of functionality like algebraic type specification where a neutral value is required by design.
const safeRecord = new Proxy( {}, { get: (handler: Record<PropertyKey, string>, name: PropertyKey) : string => { handler[name] ??= ""; return handler[name]; } } );~ 63 words -
Array and object type detection
typescriptMatching primitive types with
typeofis simple. Switching on complex types instead can be a pain - looking at you array and object. Here are two helpers that can be deployed in some conditional type switching logic.type DetectArray<T> = number extends keyof T ? true : false; // use in type switching DetectArray<string[]> // true DetectArray<{ [k: number]: unknown }> // true type DetectStringObj<T> = string extends keyof T ? true : false; DetectStringObj<{ [k: string]: unknown }> // true DetectStringObj<{ x: string }> // false, because { x: string } is a subtyped object~ 89 words
