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 Range<n, range extends any[] = []> = | |
range['length'] extends n ? range : Range<n, [...range, range['length']]> | |
type Drop1<a extends any[]> = | |
a extends [...infer inits, any] ? inits : [] | |
type Concat<a extends any[], b extends any[]> = [...a, ...b] | |
type Plus<a, b> = | |
[...Range<a>, ...Range<b>]['length'] |
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
export type TaskPriority = "user-blocking" | "user-visible" | "background"; | |
export type SchedulerPostTaskOptions = { | |
// This priority is immutable and overrides the | |
// TaskController's priority. | |
priority?: TaskPriority; | |
delay?: number; | |
signal?: TaskSignal; | |
}; |
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 TupleToList<xs> = xs extends [infer head, ...(infer tail)] | |
? [head extends any[] ? head[number] : never, ...TupleToList<tail>] | |
: []; | |
function permute<xs extends [] | [any[], ...any[][]]>([ | |
head, | |
...rest | |
]: xs): TupleToList<xs>[]; |
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 fs = require("fs"); | |
const tasks = JSON.parse(fs.readFileSync("./input-5req-2render-slow.json")); | |
// Build histogram of tasks with buckets of 1000ms | |
const histogram = tasks.reduce((acc, task) => { | |
const key = Math.floor(task.start / 1000) + ""; | |
return Object.assign(acc, { | |
[key]: (acc[key] ?? []).concat(task), | |
}); |
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
/** | |
* We call "variance" the direction of assignability between two types | |
* (in other words, which type is a subtype of the other). | |
* | |
* The same type can have a different variance in function of his position | |
* in a larger type, and this is what makes assignability in TypeScript | |
* not always straightforwards. | |
* | |
* There are 4 kinds of variance: | |
* - Covariant: if the type `a` is assignable to `a | b`. |
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
/** | |
* CancelablePromise is a wrapper around a regular Promise which | |
* can be cancelled by calling `promise.cancel()`. | |
* | |
* To do something on cancel, return a callback inside the | |
* function passed to the CancelablePromise constructor. | |
* | |
* Canceled promises will neither be rejected or resolved, | |
* but will stay unfulfilled. | |
* |
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
// Helpers | |
type Expect<T extends true> = T | |
type Equal<X, Y> = | |
(<T>() => T extends X ? 1 : 2) extends | |
(<T>() => T extends Y ? 1 : 2) | |
? true | |
: false; |
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
import mapValues from 'lodash/mapValues'; | |
export type Step<Anims> = { | |
[K in keyof Anims]: { value: number; progress: number }; | |
}; | |
export type Values<Anims> = { [K in keyof Anims]: number }; | |
export interface SpringOptions { | |
/** |
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
/** | |
* # Assigning properties to an object type in TypeScript | |
* | |
* When we want to assign some properties on a object type | |
* we usually use the `&` operator: | |
* | |
* type B = A & { someProperty: string } | |
* | |
* It seems to work at first sight, but it doesn't behave exactly | |
* as we would expect when we try to override properties that already |
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
/** | |
* # How does `A extends B` work in TypeScript? | |
* | |
* If you think about types in terms of sets containing possible values, | |
* the `string` type is the set of all possible strings, | |
* the `number` type is the set of all possible numbers, | |
* the `'hello'` type is a set containing only the string 'hello' | |
* and the `2` type is a set containing only the number 2. | |
* | |
* Then you can think of `A extends B` as asking this question: |