Skip to content

Commit 31fbe69

Browse files
fix(types): default the new memo cache type parameters
Calls that pass only the type arguments provide and cachedProvide had before keep compiling. The type generator now prints a type parameter named in another's constraint or default as a reference. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HArJAXZagrHVVNLZZk9soh
1 parent f5105b2 commit 31fbe69

4 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎lib/Compiler.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ const getConcurrentCompilationError = memoize(() =>
183183
* @typedef {{
184184
* get<K extends TupleElement>(key: K, ...rest: TupleElement[]): MemCacheValue<K> | undefined,
185185
* set<K extends TupleElement>(key: K, ...restAndValue: [...TupleElement[], MemCacheValue<K>]): void,
186-
* provide<K extends TupleElement, V, R extends TupleElement[]>(key: K, ...restAndCompute: [...R, (key: K, ...rest: [R][R extends R ? 0 : never]) => MemCacheProvided<K, V>]): MemCacheProvided<K, V>,
187-
* cachedProvide<This, V, A extends TupleElement[]>(compute: (thisArg: This, ...key: [A][A extends A ? 0 : never]) => V, thisArg: This, args: A): V,
186+
* provide<K extends TupleElement, V, R extends TupleElement[] = TupleElement[]>(key: K, ...restAndCompute: [...R, (key: K, ...rest: [R][R extends R ? 0 : never]) => MemCacheProvided<K, V>]): MemCacheProvided<K, V>,
187+
* cachedProvide<This, V, A extends TupleElement[] = TupleElement[]>(compute: (thisArg: This, ...key: [A][A extends A ? 0 : never]) => V, thisArg: This, args: A): V,
188188
* } & Omit<import("./util/WeakTupleMap")<TupleElement[], unknown>, "get" | "set" | "provide" | "cachedProvide">} MemCache
189189
*/
190190
/** @typedef {{ buildInfo: BuildInfo, references: WeakReferences | undefined, lazyRequests: string | undefined, memCache: MemCache }} ModuleMemCachesItem */

‎lib/util/WeakTupleMap.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class WeakTupleMap {
121121
/**
122122
* Returns an existing value for the tuple or computes, stores, and returns a
123123
* new one when the tuple is missing.
124-
* @template {K} A
124+
* @template {K} [A=K]
125125
* @param {[...A, (...args: A) => V]} args tuple
126126
* @returns {V} the value
127127
*/
@@ -145,7 +145,7 @@ class WeakTupleMap {
145145
* extra rest array) on every call — `ModuleGraph#cached` runs this on hot
146146
* paths where most calls hit the cache and the closure would be pure waste.
147147
* @template This
148-
* @template {K} A
148+
* @template {K} [A=K]
149149
* @param {(thisArg: This, ...args: [A][A extends A ? 0 : never]) => V} compute computer, also the first key element; `A` is read from `args`, not from it
150150
* @param {This} thisArg first argument passed to `compute`
151151
* @param {A} args remaining key elements, also passed to `compute`

‎tooling/generate-types.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,12 +2854,14 @@ const generateDeclarations = ({
28542854
let code = parsed.name;
28552855

28562856
if (state === "in type args") {
2857+
// A type parameter named inside a constraint or default is a
2858+
// reference, which declares nothing of its own.
28572859
if (parsed.constraint) {
2858-
const constraint = getCode(parsed.constraint, typeArgs, state);
2860+
const constraint = getCode(parsed.constraint, typeArgs);
28592861
code += ` extends ${constraint}`;
28602862
}
28612863
if (parsed.defaultValue) {
2862-
const defaultValue = getCode(parsed.defaultValue, typeArgs, state);
2864+
const defaultValue = getCode(parsed.defaultValue, typeArgs);
28632865
code += ` = ${defaultValue}`;
28642866
}
28652867
}

‎types.d.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19843,14 +19843,14 @@ type MemCache = {
1984319843
key: K,
1984419844
...restAndValue: [...TupleElement[], MemCacheValue<K>]
1984519845
): void;
19846-
provide<K extends TupleElement, V, R extends TupleElement[]>(
19846+
provide<K extends TupleElement, V, R extends TupleElement[] = TupleElement[]>(
1984719847
key: K,
1984819848
...restAndCompute: [
1984919849
...R,
1985019850
(key: K, ...rest: [R][R extends R ? 0 : never]) => MemCacheProvided<K, V>
1985119851
]
1985219852
): MemCacheProvided<K, V>;
19853-
cachedProvide<This, V, A extends TupleElement[]>(
19853+
cachedProvide<This, V, A extends TupleElement[] = TupleElement[]>(
1985419854
compute: (thisArg: This, ...key: [A][A extends A ? 0 : never]) => V,
1985519855
thisArg: This,
1985619856
args: A
@@ -35287,7 +35287,7 @@ declare abstract class WeakTupleMap<K extends TupleElement[], V> {
3528735287
* Returns an existing value for the tuple or computes, stores, and returns a
3528835288
* new one when the tuple is missing.
3528935289
*/
35290-
provide<A extends TupleElement[]>(...args: [...A, (...args: A) => V]): V;
35290+
provide<A extends TupleElement[] = K>(...args: [...A, (...args: A) => V]): V;
3529135291

3529235292
/**
3529335293
* Memoizes `compute(thisArg, ...args)` under the tuple key `[compute,
@@ -35296,7 +35296,7 @@ declare abstract class WeakTupleMap<K extends TupleElement[], V> {
3529635296
* extra rest array) on every call — `ModuleGraph#cached` runs this on hot
3529735297
* paths where most calls hit the cache and the closure would be pure waste.
3529835298
*/
35299-
cachedProvide<This, A extends TupleElement[]>(
35299+
cachedProvide<This, A extends TupleElement[] = K>(
3530035300
compute: (thisArg: This, ...args: [A][A extends A ? 0 : never]) => V,
3530135301
thisArg: This,
3530235302
args: A

0 commit comments

Comments
 (0)