- NOTE: This is a markdown adaptation of the original forked gist, additional file in this gist is an adaptation of the original post.
For the best guide, use search keyword: chmod. It should scroll down to:
//#region Types | |
// Just here to validate that the new signature is identical to the es5 type declaration | |
type Array$join$primordial_Signature = (separator?: string) => string | |
declare interface Array<T> | |
{ | |
separator?: string; | |
join: Array$join$primordial_Signature; |
{ | |
"scripts": [], | |
"showConsole": true, | |
"scriptType": "text/javascript", | |
"layout": "splitLeft" | |
} |
type AnyArray = any[]; | |
type NotArray = Exclude<any, AnyArray>; | |
//#region ifArray | |
//#region Definition | |
function ifArray<T, F, O extends Array<any> = Array<any>>(obj: O, isTrue: T, isFalse: F): T; | |
function ifArray<T, F, O extends Exclude<any, any[]>>(obj: O, isTrue: T, isFalse: F): F; | |
function ifArray<T, F, O>(obj: O, isTrue: T, isFalse: F): T | F |
div#app |
/** | |
* Casting regexp match/exec results will allow for autocompletion of the keys supplied in union | |
* to `Groups` generic parameter: | |
* ``` ts | |
* const execResult = /(?<test>capture)/.exec('test') as GroupedRegExpExecArray<'test'>; | |
* execResult.groups. // <TAB> => test?: string | |
* | |
* const matchResult = 'test'.match(/(?<test>capture)/) as GroupedRegExpMatchArray<'test'|'capture'>; | |
* matchResult.groups. // <TAB> => (property) capture?: string | |
* // (property) test?: string |
///<reference lib="es2019.array"/> | |
//#region Util | |
const Identity = <V>(value: V): V => value; | |
type Identity = typeof Identity; | |
const asString = (value: any): string => String(value); | |
type ToString = (value: any) => string; |
/** | |
* Inspired by [Drew Colthorp's blog post, Flavoring: Flexible Nominal Typing for TypeScript](https://spin.atomicobject.com/2018/01/15/typescript-flexible-nominal-typing) | |
*/ | |
/** | |
* Last form of an attempt to define a generic constrained to `unique symbol` for | |
* the property symbol (`NominalIdentifierSymbol` in this case). | |
* | |
* 'NominalIdentifierSymbol' is declared but its value is never read.(6133) | |
* VVVVVVVVVVVVVVVVVVVVVV |
/** | |
* @fileoverview | |
* Typescript Pattern Matching | |
* @description | |
* From [@fillopeter's Medium post](https://medium.com/@fillopeter/pattern-matching-with-typescript-done-right-94049ddd671c), | |
* _“Pattern matching” with Typescript done right_ | |
*/ | |
class Square { | |
type = "Square" as const |
For the best guide, use search keyword: chmod. It should scroll down to:
Every time I start a new project, I want to pull in a log
function that allows the same functionality as the console.log
, including the full functionality of the Console API.
There are a lot of ways to do this, but many are lacking. A common problem with wrapper functions is that the line number that shows up next to the log is the line number of the log function itself, not where log
was invoked. There are also times where the arguments get logged in a way that isn't quite the same as the native function.
This is an attempt to once and for all document the function that I pull in to new projects. There are two different options: