This file contains 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
var Limit; | |
(function (Limit) { | |
Limit[Limit["All"] = 0] = "All"; | |
Limit[Limit["Two"] = 1] = "Two"; | |
Limit[Limit["One"] = 2] = "One"; | |
})(Limit || (Limit = {})); | |
let config; | |
let rootDocument; | |
export function finder(input, options) { | |
if (input.nodeType !== Node.ELEMENT_NODE) { |
This file contains 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
function exampleOne() { | |
console.log('One'); | |
return Promise.resolve() | |
.then(() => console.log('Two')) | |
.catch(() => console.log('Three')) | |
.finally(() => console.log('Four')); | |
} | |
function exampleTwo() { |
This file contains 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 path = require('path'); | |
const { createServer } = require('vite'); | |
module.exports = async (on, config) => { | |
const host = process.env.HOST || 'localhost'; | |
const port = process.env.PORT || 3000; | |
// Vite config | |
const viteConfig = { | |
configFile: path.resolve(__dirname, "../vite.config.ts"), |
This file contains 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 _Fib<NUM extends any[]> = NUM['length'] extends 1 | 0 | |
? NUM | |
: Add<_Fib<Minus1<NUM>>, _Fib<Minus2<NUM>>>; | |
type Fib<N extends number> = _Fib<ArrayOfSize<N>>['length']; | |
type F1 = Fib<1>; // 1 | |
type F2 = Fib<2>; // 1 | |
type F3 = Fib<3>; // 2 |
This file contains 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 Plus1<A extends any[]> = [true, ...A]; | |
type Add<A extends any[], B extends any[]> = [...A, ...B]; | |
type Minus1<A extends any[]> = A extends readonly [any?, ...infer U] ? U : [...A]; | |
type Minus2<A extends any[]> = Minus1<Minus1<A>>; | |
// verify | |
type D = Plus1<A>; // [true, true, true, true] | |
type E = Minus1<A>; // [true, true] | |
type F = Minus2<A>; // [true] |
This file contains 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
// number -> array | |
type ArrayOfSize<N extends number> = N extends N ? (number extends N ? boolean[] : _ArrayOfSize<N, []>) : never; | |
type _ArrayOfSize<N extends number, R extends unknown[]> = R['length'] extends N ? R : _ArrayOfSize<N, [true, ...R]>; | |
// verify | |
type A = ArrayOfSize<3>; // [true, true, true] | |
type B = ArrayOfSize<1>; // [true] | |
type C = ArrayOfSize<0>; // [] |
This file contains 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
// Awaiting promises | |
type Awaited<T> = | |
T extends null | undefined ? T : | |
T extends PromiseLike<infer U> ? Awaited<U> : | |
T; | |
type P1 = Awaited<Promise<string>>; // string | |
type P2 = Awaited<Promise<Promise<string>>>; // string | |
type P3 = Awaited<Promise<string | Promise<Promise<number> | undefined>>; // string | number | undefined |
This file contains 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
// Variadic tuple elements | |
type Foo<T extends unknown[]> = [string, ...T, number]; | |
type T1 = Foo<[boolean]>; // [string, boolean, number] | |
type T2 = Foo<[number, number]>; // [string, number, number, number] | |
type T3 = Foo<[]>; // [string, number] | |
// Strongly typed tuple concatenation |
This file contains 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 Unpacked<T> = | |
T extends (infer U)[] ? U : | |
T extends (...args: any[]) => infer U ? U : | |
T extends Promise<infer U> ? U : | |
T; | |
type T0 = Unpacked<string>; // string | |
type T1 = Unpacked<string[]>; // string | |
type T2 = Unpacked<() => string>; // string | |
type T3 = Unpacked<Promise<string>>; // string |
This file contains 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 TypeName<T> = | |
T extends string ? "string" : | |
T extends number ? "number" : | |
T extends boolean ? "boolean" : | |
T extends undefined ? "undefined" : | |
T extends Function ? "function" : | |
"object"; | |
type T0 = TypeName<string>; // "string" | |
type T1 = TypeName<"a">; // "string" |
NewerOlder