Split out of #15123 so that PR can land. Raised by Devin: #15123 (comment)
Problem
WorkerPoolOptionsContext.inject was changed from typeof inject (vitest's) to a widened signature in packages/vitest-pool-workers/src/pool/plugin.ts:
inject: <T = unknown>(key: string) => T;
The change was deliberate, and the reason is documented in place: binding to typeof inject from this package's copy of vitest makes keyof ProvidedContext resolve to never, because a consumer's declare module "vitest" augmentation only applies to the consumer's own copy, and pnpm can resolve two separate virtual-store instances. So the previous typing was broken in its own way.
The cost is that inference and key checking are both gone:
- The return type now defaults to
unknown, so anywhere the value is passed to a typed parameter or assigned to a typed variable, consumers need an explicit type argument. Our own fixture had to become inject<number>("echoServerPort") in fixtures/vitest-pool-workers-examples/hyperdrive/vitest.config.ts.
key is string, so a misspelled key is no longer a type error.
There is also a semver question: this is a change to a public type that can require consumers to edit their config, which is not obviously a patch.
Possible direction
Keep an overload that preserves inference for known keys while still accepting arbitrary strings, e.g.:
inject: {
<K extends keyof ProvidedContext>(key: K): ProvidedContext[K];
<T = unknown>(key: string): T;
};
This needs checking against the actual failure it was working around — if keyof ProvidedContext resolves to never in the cross-copy case, the first overload may simply never match and the fallback would still apply, but that wants verifying with a real pnpm-resolved consumer rather than assumed.
Acceptance
- Consumers using a
ProvidedContext augmentation get inference and key checking back, without reintroducing the never resolution problem.
- If the public type ends up changing in a way consumers must react to, the changeset is classified accordingly.
Split out of #15123 so that PR can land. Raised by Devin: #15123 (comment)
Problem
WorkerPoolOptionsContext.injectwas changed fromtypeof inject(vitest's) to a widened signature inpackages/vitest-pool-workers/src/pool/plugin.ts:The change was deliberate, and the reason is documented in place: binding to
typeof injectfrom this package's copy of vitest makeskeyof ProvidedContextresolve tonever, because a consumer'sdeclare module "vitest"augmentation only applies to the consumer's own copy, and pnpm can resolve two separate virtual-store instances. So the previous typing was broken in its own way.The cost is that inference and key checking are both gone:
unknown, so anywhere the value is passed to a typed parameter or assigned to a typed variable, consumers need an explicit type argument. Our own fixture had to becomeinject<number>("echoServerPort")infixtures/vitest-pool-workers-examples/hyperdrive/vitest.config.ts.keyisstring, so a misspelled key is no longer a type error.There is also a semver question: this is a change to a public type that can require consumers to edit their config, which is not obviously a
patch.Possible direction
Keep an overload that preserves inference for known keys while still accepting arbitrary strings, e.g.:
This needs checking against the actual failure it was working around — if
keyof ProvidedContextresolves toneverin the cross-copy case, the first overload may simply never match and the fallback would still apply, but that wants verifying with a real pnpm-resolved consumer rather than assumed.Acceptance
ProvidedContextaugmentation get inference and key checking back, without reintroducing theneverresolution problem.