Skip to content
Myr

types-external.ts

This file

Path

src/types/types-external.ts

257 lines · 8.0 KiB · TypeScript

Last changed by

chore: typo dormal -> normal (#910)Jacob Eldredbefore adoption49f94e1

History of this file

Take it

The walk stopped after 200 commits: lines older than 497d1a0 point at it.

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 1–2why, one step back
1import {Nothing} from "../internal"
2

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

line 3why, one step back
3type AnyFunc = (...args: any[]) => any

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 4why, one step back
4

fix: Add a type-checking fast path for primitive types (#755)Andrew Caseybefore adoptiond395efe

lines 5–6why, one step back
5type PrimitiveType = number | string | boolean
6

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 7why, one step back
7/** Object types that should never be mapped */

fix: Add a type-checking fast path for primitive types (#755)Andrew Caseybefore adoptiond395efe

line 8why, one step back
8type AtomicObject = Function | Promise<any> | Date | RegExp

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 9–10why, one step back
9
10/**

Fix typo (#985)ddronebefore adoptionba0a79a

line 11why, one step back
11 * If the lib "ES2015.Collection" is not included in tsconfig.json,

fix: skip ReadonlyMap and ReadonlySet types when not available (#653). Fixes #624Lenz Weberbefore adoption12f4cf8

line 12why, one step back
12 * types like ReadonlyArray, WeakMap etc. fall back to `any` (specified nowhere)

Fix typo (#985)ddronebefore adoptionba0a79a

line 13why, one step back
13 * or `{}` (from the node types), in both cases entering an infinite recursion in

fix: skip ReadonlyMap and ReadonlySet types when not available (#653). Fixes #624Lenz Weberbefore adoption12f4cf8

lines 14–27why, one step back
14 * pattern matching type mappings
15 * This type can be used to cast these types to `void` in these cases.16 */17export type IfAvailable<T, Fallback = void> =18 // fallback if any19 true | false extends (T extends never20 ? true21 : false)22 ? Fallback // fallback if empty type23 : keyof T extends never24 ? Fallback // original type25 : T2627/**

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 28–30why, one step back
28 * These should also never be mapped but must be tested after regular Map and
29 * Set30 */

fix: skip ReadonlyMap and ReadonlySet types when not available (#653). Fixes #624Lenz Weberbefore adoption12f4cf8

line 31why, one step back
31type WeakReferences = IfAvailable<WeakMap<any, any>> | IfAvailable<WeakSet<any>>

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 32why, one step back
32

fix: Use a named type for Draft object for smaller type declaration filesMichel Weststratebefore adoptiona1a0da0

lines 33–34why, one step back
33export type WritableDraft<T> = {-readonly [K in keyof T]: Draft<T[K]>}
34

chore: Add note explaining Draft type (#967)Stephen Michelbefore adoption54ecc9b

line 35why, one step back
35/** Convert a readonly type into a mutable type, if possible */

fix: Add a type-checking fast path for primitive types (#755)Andrew Caseybefore adoptiond395efe

line 36why, one step back
36export type Draft<T> = T extends PrimitiveType

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 37why, one step back
37 ? T

fix: Add a type-checking fast path for primitive types (#755)Andrew Caseybefore adoptiond395efe

lines 38–39why, one step back
38 : T extends AtomicObject
39 ? T

fix: skip ReadonlyMap and ReadonlySet types when not available (#653). Fixes #624Lenz Weberbefore adoption12f4cf8

line 40why, one step back
40 : T extends IfAvailable<ReadonlyMap<infer K, infer V>> // Map extends ReadonlyMap

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 41why, one step back
41 ? Map<Draft<K>, Draft<V>>

fix: skip ReadonlyMap and ReadonlySet types when not available (#653). Fixes #624Lenz Weberbefore adoption12f4cf8

line 42why, one step back
42 : T extends IfAvailable<ReadonlySet<infer V>> // Set extends ReadonlySet

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 43–46why, one step back
43 ? Set<Draft<V>>
44 : T extends WeakReferences45 ? T46 : T extends object

fix: Use a named type for Draft object for smaller type declaration filesMichel Weststratebefore adoptiona1a0da0

line 47why, one step back
47 ? WritableDraft<T>

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 48–50why, one step back
48 : T
4950/** Convert a mutable type into a readonly type */

fix: Add a type-checking fast path for primitive types (#755)Andrew Caseybefore adoptiond395efe

lines 51–53why, one step back
51export type Immutable<T> = T extends PrimitiveType
52 ? T53 : T extends AtomicObject

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 54why, one step back
54 ? T

fix: skip ReadonlyMap and ReadonlySet types when not available (#653). Fixes #624Lenz Weberbefore adoption12f4cf8

line 55why, one step back
55 : T extends IfAvailable<ReadonlyMap<infer K, infer V>> // Map extends ReadonlyMap

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 56why, one step back
56 ? ReadonlyMap<Immutable<K>, Immutable<V>>

fix: skip ReadonlyMap and ReadonlySet types when not available (#653). Fixes #624Lenz Weberbefore adoption12f4cf8

line 57why, one step back
57 : T extends IfAvailable<ReadonlySet<infer V>> // Set extends ReadonlySet

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 58–83why, one step back
58 ? ReadonlySet<Immutable<V>>
59 : T extends WeakReferences60 ? T61 : T extends object62 ? {readonly [K in keyof T]: Immutable<T[K]>}63 : T6465export interface Patch {66 op: "replace" | "remove" | "add"67 path: (string | number)[]68 value?: any69}7071export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void7273/** Converts `nothing` into `undefined` */74type FromNothing<T> = T extends Nothing ? undefined : T7576/** The inferred return type of `produce` */77export type Produced<Base, Return> = Return extends void78 ? Base79 : Return extends Promise<infer Result>80 ? Promise<Result extends void ? Base : FromNothing<Result>>81 : FromNothing<Return>8283/**

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

lines 84–156why, one step back
84 * Utility types
85 */86type PatchesTuple<T> = readonly [T, Patch[], Patch[]]8788type ValidRecipeReturnType<State> =89 | State90 | void91 | undefined92 | (State extends undefined ? Nothing : never)9394type ValidRecipeReturnTypePossiblyPromise<State> =95 | ValidRecipeReturnType<State>96 | Promise<ValidRecipeReturnType<State>>9798type PromisifyReturnIfNeeded<99 State,100 Recipe extends AnyFunc,101 UsePatches extends boolean102> = ReturnType<Recipe> extends Promise<any>103 ? Promise<UsePatches extends true ? PatchesTuple<State> : State>104 : UsePatches extends true105 ? PatchesTuple<State>106 : State107108/**109 * Core Producer inference110 */111type InferRecipeFromCurried<Curried> = Curried extends (112 base: infer State,113 ...rest: infer Args114) => any // extra assertion to make sure this is a proper curried function (state, args) => state115 ? ReturnType<Curried> extends State116 ? (117 draft: Draft<State>,118 ...rest: Args119 ) => ValidRecipeReturnType<Draft<State>>120 : never121 : never122123type InferInitialStateFromCurried<Curried> = Curried extends (124 base: infer State,125 ...rest: any[]126) => any // extra assertion to make sure this is a proper curried function (state, args) => state127 ? State128 : never129130type InferCurriedFromRecipe<131 Recipe,132 UsePatches extends boolean133> = Recipe extends (draft: infer DraftState, ...args: infer RestArgs) => any // verify return type134 ? ReturnType<Recipe> extends ValidRecipeReturnTypePossiblyPromise<DraftState>135 ? (136 base: Immutable<DraftState>,137 ...args: RestArgs138 ) => PromisifyReturnIfNeeded<DraftState, Recipe, UsePatches> // N.b. we return mutable draftstate, in case the recipe's first arg isn't read only, and that isn't expected as output either139 : never // incorrect return type140 : never // not a function141142type InferCurriedFromInitialStateAndRecipe<143 State,144 Recipe,145 UsePatches extends boolean146> = Recipe extends (147 draft: Draft<State>,148 ...rest: infer RestArgs149) => ValidRecipeReturnTypePossiblyPromise<State>150 ? (151 base?: State | undefined,152 ...args: RestArgs153 ) => PromisifyReturnIfNeeded<State, Recipe, UsePatches>154 : never // recipe doesn't match initial state155156/**

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 157–175why, one step back
157 * The `produce` function takes a value and a "recipe function" (whose
158 * return value often depends on the base state). The recipe function is159 * free to mutate its first argument however it wants. All mutations are160 * only ever applied to a __copy__ of the base state.161 *162 * Pass only a function to create a "curried producer" which relieves you163 * from passing the recipe function every time.164 *165 * Only plain objects and arrays are made mutable. All other objects are166 * considered uncopyable.167 *168 * Note: This function is __bound__ to its `Immer` instance.169 *170 * @param {any} base - the initial state171 * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified172 * @param {Function} patchListener - optional function that will be called with all the patches produced here173 * @returns {any} a new state, or the initial state if nothing was modified174 */175export interface IProduce {

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

lines 176–180why, one step back
176 /** Curried producer that infers the recipe from the curried output function (e.g. when passing to setState) */
177 <Curried>(178 recipe: InferRecipeFromCurried<Curried>,179 initialState?: InferInitialStateFromCurried<Curried>180 ): Curried

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 181why, one step back
181

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

lines 182–210why, one step back
182 /** Curried producer that infers curried from the recipe */
183 <Recipe extends AnyFunc>(recipe: Recipe): InferCurriedFromRecipe<184 Recipe,185 false186 >187188 /** Curried producer that infers curried from the State generic, which is explicitly passed in. */189 <State>(190 recipe: (191 state: Draft<State>,192 initialState: State193 ) => ValidRecipeReturnType<State>194 ): (state?: State) => State195 <State, Args extends any[]>(196 recipe: (197 state: Draft<State>,198 ...args: Args199 ) => ValidRecipeReturnType<State>,200 initialState: State201 ): (state?: State, ...args: Args) => State202 <State>(recipe: (state: Draft<State>) => ValidRecipeReturnType<State>): (203 state: State204 ) => State205 <State, Args extends any[]>(206 recipe: (state: Draft<State>, ...args: Args) => ValidRecipeReturnType<State>207 ): (state: State, ...args: Args) => State208209 /** Curried producer with initial state, infers recipe from initial state */210 <State, Recipe extends Function>(

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 211why, one step back
211 recipe: Recipe,

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

lines 212–213why, one step back
212 initialState: State
213 ): InferCurriedFromInitialStateAndRecipe<State, Recipe, false>

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 214–215why, one step back
214
215 /** Normal producer */

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

line 216why, one step back
216 <Base, D = Draft<Base>>( // By using a default inferred D, rather than Draft<Base> in the recipe, we can override it.

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 217why, one step back
217 base: Base,

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

line 218why, one step back
218 recipe: (draft: D) => ValidRecipeReturnType<D>,

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 219why, one step back
219 listener?: PatchListener

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

line 220why, one step back
220 ): Base

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

line 221why, one step back
221

chore: typo dormal -> normal (#910)Jacob Eldredbefore adoption49f94e1

line 222why, one step back
222 /** Promisified normal producer */

fix: #785 fix type inference for produce incorrectly inferring promise (#786)hardfistbefore adoption6555173

lines 223–227why, one step back
223 <Base, D = Draft<Base>>(
224 base: Base,225 recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,226 listener?: PatchListener227 ): Promise<Base>

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 228–236why, one step back
228}
229230/**231 * Like `produce`, but instead of just returning the new state,232 * a tuple is returned with [nextState, patches, inversePatches]233 *234 * Like produce, this function supports currying235 */236export interface IProduceWithPatches {

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

lines 237–239why, one step back
237 // Types copied from IProduce, wrapped with PatchesTuple
238 <Recipe extends AnyFunc>(recipe: Recipe): InferCurriedFromRecipe<Recipe, true>239 <State, Recipe extends Function>(

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 240why, one step back
240 recipe: Recipe,

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

lines 241–243why, one step back
241 initialState: State
242 ): InferCurriedFromInitialStateAndRecipe<State, Recipe, true>243 <Base, D = Draft<Base>>(

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

line 244why, one step back
244 base: Base,

fix: consistent recipe return type in produceWithPatches (#934)Myles Jbefore adoption220d61d

line 245why, one step back
245 recipe: (draft: D) => ValidRecipeReturnType<D>,

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

line 246why, one step back
246 listener?: PatchListener

fix: produceWithPatches should not wrap result in Immutable, fixes #850, #881Michel Weststratebefore adoptiond8f2636

line 247why, one step back
247 ): PatchesTuple<Base>

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

lines 248–249why, one step back
248 <Base, D = Draft<Base>>(
249 base: Base,

fix: consistent recipe return type in produceWithPatches (#934)Myles Jbefore adoption220d61d

line 250why, one step back
250 recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,

feature: Improved typescript typesMichel Weststratebefore adoption2c2f30e

line 251why, one step back
251 listener?: PatchListener

fix: incorrect return type for async produceWithPatches (#933)Myles Jbefore adoption9f7623d

line 252why, one step back
252 ): Promise<PatchesTuple<Base>>

fix: Don't recurse into non-enumerable members when freezing tree. Fixes #590Michel Weststratebefore adoption497d1a0

lines 253–257why, one step back
253}
254255// Fixes #507: bili doesn't export the types of this file if there is no actual source in it..256// hopefully it get's tree-shaken away for everyone :)257export function never_used() {}