Skip to content

Commit 2d2f2e5

Browse files
authored
fix(types): explicitly set Vite hooks' this to void (#9885)
1 parent 6be971e commit 2d2f2e5

4 files changed

Lines changed: 18 additions & 6 deletions

File tree

packages/vite/src/node/plugin.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export interface Plugin extends RollupPlugin {
5555
/**
5656
* Apply the plugin only for serve or build, or on certain conditions.
5757
*/
58-
apply?: 'serve' | 'build' | ((config: UserConfig, env: ConfigEnv) => boolean)
58+
apply?:
59+
| 'serve'
60+
| 'build'
61+
| ((this: void, config: UserConfig, env: ConfigEnv) => boolean)
5962
/**
6063
* Modify vite config before it's resolved. The hook can either mutate the
6164
* passed-in config directly, or return a partial config object that will be
@@ -66,14 +69,17 @@ export interface Plugin extends RollupPlugin {
6669
*/
6770
config?: ObjectHook<
6871
(
72+
this: void,
6973
config: UserConfig,
7074
env: ConfigEnv
7175
) => UserConfig | null | void | Promise<UserConfig | null | void>
7276
>
7377
/**
7478
* Use this hook to read and store the final resolved vite config.
7579
*/
76-
configResolved?: ObjectHook<(config: ResolvedConfig) => void | Promise<void>>
80+
configResolved?: ObjectHook<
81+
(this: void, config: ResolvedConfig) => void | Promise<void>
82+
>
7783
/**
7884
* Configure the vite server. The hook receives the {@link ViteDevServer}
7985
* instance. This can also be used to store a reference to the server
@@ -126,6 +132,7 @@ export interface Plugin extends RollupPlugin {
126132
*/
127133
handleHotUpdate?: ObjectHook<
128134
(
135+
this: void,
129136
ctx: HmrContext
130137
) => Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>
131138
>

packages/vite/src/node/plugins/html.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ export interface IndexHtmlTransformContext {
846846
}
847847

848848
export type IndexHtmlTransformHook = (
849+
this: void,
849850
html: string,
850851
ctx: IndexHtmlTransformContext
851852
) => IndexHtmlTransformResult | void | Promise<IndexHtmlTransformResult | void>

packages/vite/src/node/preview.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ export interface PreviewServer {
6262
printUrls(): void
6363
}
6464

65-
export type PreviewServerHook = (server: {
66-
middlewares: Connect.Server
67-
httpServer: http.Server
68-
}) => (() => void) | void | Promise<(() => void) | void>
65+
export type PreviewServerHook = (
66+
this: void,
67+
server: {
68+
middlewares: Connect.Server
69+
httpServer: http.Server
70+
}
71+
) => (() => void) | void | Promise<(() => void) | void>
6972

7073
/**
7174
* Starts the Vite server in preview mode, to simulate a production deployment

packages/vite/src/node/server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export interface FileSystemServeOptions {
151151
}
152152

153153
export type ServerHook = (
154+
this: void,
154155
server: ViteDevServer
155156
) => (() => void) | void | Promise<(() => void) | void>
156157

0 commit comments

Comments
 (0)