Skip to content

Commit 0eda99d

Browse files
authored
fix(api): correct project.provide type (#5959)
1 parent fca8b92 commit 0eda99d

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

packages/vitest/src/integrations/inject.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { getWorkerState } from '../utils/global'
55
* Gives access to injected context provided from the main thread.
66
* This usually returns a value provided by `globalSetup` or an external library.
77
*/
8-
export function inject<T extends keyof ProvidedContext>(
8+
export function inject<T extends keyof ProvidedContext & string>(
99
key: T,
1010
): ProvidedContext[T] {
1111
const workerState = getWorkerState()
12-
return workerState.providedContext[key]
12+
return workerState.providedContext[key] as ProvidedContext[T]
1313
}

packages/vitest/src/node/core.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class Vitest {
183183
}
184184
}
185185

186-
public provide<T extends keyof ProvidedContext>(key: T, value: ProvidedContext[T]) {
186+
public provide<T extends keyof ProvidedContext & string>(key: T, value: ProvidedContext[T]) {
187187
this.getCoreWorkspaceProject().provide(key, value)
188188
}
189189

packages/vitest/src/node/globalSetup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ResolvedConfig } from '../types/config'
55

66
export interface GlobalSetupContext {
77
config: ResolvedConfig
8-
provide: <T extends keyof ProvidedContext>(
8+
provide: <T extends keyof ProvidedContext & string>(
99
key: T,
1010
value: ProvidedContext[T]
1111
) => void

packages/vitest/src/node/workspace.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ export class WorkspaceProject {
115115
return this.ctx.getCoreWorkspaceProject() === this
116116
}
117117

118-
provide = <T extends keyof ProvidedContext>(
118+
provide<T extends keyof ProvidedContext & string>(
119119
key: T,
120120
value: ProvidedContext[T],
121-
) => {
121+
) {
122122
try {
123123
structuredClone(value)
124124
}
@@ -157,7 +157,7 @@ export class WorkspaceProject {
157157

158158
for (const globalSetupFile of this._globalSetups) {
159159
const teardown = await globalSetupFile.setup?.({
160-
provide: this.provide,
160+
provide: (key, value) => this.provide(key, value),
161161
config: this.config,
162162
})
163163
if (teardown == null || !!globalSetupFile.teardown) {

0 commit comments

Comments
 (0)