Skip to content

Commit 97f2036

Browse files
authored
fix: exact optional property types (#500)
1 parent a1932e6 commit 97f2036

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/types.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,46 +33,46 @@ export type Nullable<T> = T | null | undefined
3333
export type Arrayable<T> = T | Array<T>
3434

3535
export interface SourceMapCompact {
36-
file?: string
36+
file?: string | undefined
3737
mappings: string
3838
names: string[]
39-
sourceRoot?: string
39+
sourceRoot?: string | undefined
4040
sources: string[]
4141
// In magic-string v0.27.0, `sourcesContent` becomes nullable, while rollup haven't catch up yet
42-
sourcesContent?: (string | null)[]
42+
sourcesContent?: (string | null)[] | undefined
4343
version: number
4444
}
4545

46-
export type TransformResult = string | { code: string, map?: SourceMapInput | SourceMapCompact | null } | null | undefined | void
46+
export type TransformResult = string | { code: string, map?: SourceMapInput | SourceMapCompact | null | undefined } | null | undefined | void
4747

48-
export interface ExternalIdResult { id: string, external?: boolean }
48+
export interface ExternalIdResult { id: string, external?: boolean | undefined }
4949

5050
export type NativeBuildContext
51-
= { framework: 'webpack', compiler: WebpackCompiler, compilation?: WebpackCompilation, loaderContext?: WebpackLoaderContext<{ unpluginName: string }> }
51+
= { framework: 'webpack', compiler: WebpackCompiler, compilation?: WebpackCompilation | undefined, loaderContext?: WebpackLoaderContext<{ unpluginName: string }> | undefined }
5252
| { framework: 'esbuild', build: PluginBuild }
53-
| { framework: 'rspack', compiler: RspackCompiler, compilation: RspackCompilation, loaderContext?: RspackLoaderContext }
53+
| { framework: 'rspack', compiler: RspackCompiler, compilation: RspackCompilation, loaderContext?: RspackLoaderContext | undefined }
5454
| { framework: 'farm', context: FarmCompilationContext }
5555

5656
export interface UnpluginBuildContext {
5757
addWatchFile: (id: string) => void
5858
emitFile: (emittedFile: EmittedAsset) => void
5959
getWatchFiles: () => string[]
6060
parse: (input: string, options?: any) => AstNode
61-
getNativeBuildContext?: () => NativeBuildContext
61+
getNativeBuildContext?: (() => NativeBuildContext) | undefined
6262
}
6363

6464
export type StringOrRegExp = string | RegExp
6565
export type FilterPattern = Arrayable<StringOrRegExp>
6666
export type StringFilter
6767
= | FilterPattern
68-
| { include?: FilterPattern, exclude?: FilterPattern }
68+
| { include?: FilterPattern | undefined, exclude?: FilterPattern | undefined }
6969
export interface HookFilter {
70-
id?: StringFilter
71-
code?: StringFilter
70+
id?: StringFilter | undefined
71+
code?: StringFilter | undefined
7272
}
7373

7474
export interface ObjectHook<T extends HookFnMap[keyof HookFnMap], F extends keyof HookFilter> {
75-
filter?: Pick<HookFilter, F>
75+
filter?: Pick<HookFilter, F> | undefined
7676
handler: T
7777
}
7878
export type Hook<
@@ -102,52 +102,52 @@ export interface UnpluginOptions {
102102
name: string
103103
enforce?: 'post' | 'pre' | undefined
104104

105-
buildStart?: HookFnMap['buildStart']
106-
buildEnd?: HookFnMap['buildEnd']
107-
transform?: Hook<HookFnMap['transform'], 'code' | 'id'>
108-
load?: Hook<HookFnMap['load'], 'id'>
109-
resolveId?: Hook<HookFnMap['resolveId'], 'id'>
110-
writeBundle?: HookFnMap['writeBundle']
105+
buildStart?: HookFnMap['buildStart'] | undefined
106+
buildEnd?: HookFnMap['buildEnd'] | undefined
107+
transform?: Hook<HookFnMap['transform'], 'code' | 'id'> | undefined
108+
load?: Hook<HookFnMap['load'], 'id'> | undefined
109+
resolveId?: Hook<HookFnMap['resolveId'], 'id'> | undefined
110+
writeBundle?: HookFnMap['writeBundle'] | undefined
111111

112-
watchChange?: (this: UnpluginBuildContext, id: string, change: { event: 'create' | 'update' | 'delete' }) => void
112+
watchChange?: ((this: UnpluginBuildContext, id: string, change: { event: 'create' | 'update' | 'delete' }) => void) | undefined
113113

114114
/**
115115
* Custom predicate function to filter modules to be loaded.
116116
* When omitted, all modules will be included (might have potential perf impact on Webpack).
117117
*
118118
* @deprecated Use `load.filter` instead.
119119
*/
120-
loadInclude?: (id: string) => boolean | null | undefined
120+
loadInclude?: ((id: string) => boolean | null | undefined) | undefined
121121
/**
122122
* Custom predicate function to filter modules to be transformed.
123123
* When omitted, all modules will be included (might have potential perf impact on Webpack).
124124
*
125125
* @deprecated Use `transform.filter` instead.
126126
*/
127-
transformInclude?: (id: string) => boolean | null | undefined
127+
transformInclude?: ((id: string) => boolean | null | undefined) | undefined
128128

129129
// framework specify extends
130-
rollup?: Partial<RollupPlugin>
131-
webpack?: (compiler: WebpackCompiler) => void
132-
rspack?: (compiler: RspackCompiler) => void
133-
vite?: Partial<VitePlugin>
134-
unloader?: Partial<UnloaderPlugin>
135-
rolldown?: Partial<RolldownPlugin>
130+
rollup?: Partial<RollupPlugin> | undefined
131+
webpack?: ((compiler: WebpackCompiler) => void) | undefined
132+
rspack?: ((compiler: RspackCompiler) => void) | undefined
133+
vite?: Partial<VitePlugin> | undefined
134+
unloader?: Partial<UnloaderPlugin> | undefined
135+
rolldown?: Partial<RolldownPlugin> | undefined
136136
esbuild?: {
137137
// using regexp in esbuild improves performance
138-
onResolveFilter?: RegExp
139-
onLoadFilter?: RegExp
140-
loader?: Loader | ((code: string, id: string) => Loader)
141-
setup?: (build: PluginBuild) => void | Promise<void>
142-
config?: (options: BuildOptions) => void
143-
}
144-
farm?: Partial<FarmPlugin>
138+
onResolveFilter?: RegExp | undefined
139+
onLoadFilter?: RegExp | undefined
140+
loader?: Loader | ((code: string, id: string) => Loader) | undefined
141+
setup?: ((build: PluginBuild) => void | Promise<void>) | undefined
142+
config?: ((options: BuildOptions) => void) | undefined
143+
} | undefined
144+
farm?: Partial<FarmPlugin> | undefined
145145
}
146146

147147
export interface ResolvedUnpluginOptions extends UnpluginOptions {
148148
// injected internal objects
149-
__vfs?: VirtualModulesPlugin
150-
__vfsModules?: Map<string, Promise<string>> | Set<string>
149+
__vfs?: VirtualModulesPlugin | undefined
150+
__vfsModules?: Map<string, Promise<string>> | Set<string> | undefined
151151
__virtualModulePrefix: string
152152
}
153153

@@ -156,7 +156,7 @@ Nested extends true
156156
? Array<UnpluginOptions>
157157
: UnpluginOptions
158158
export type UnpluginFactoryOutput<UserOptions, Return> = undefined extends UserOptions
159-
? (options?: UserOptions) => Return
159+
? (options?: UserOptions | undefined) => Return
160160
: (options: UserOptions) => Return
161161

162162
export interface UnpluginInstance<UserOptions, Nested extends boolean = boolean> {
@@ -179,25 +179,25 @@ export type UnpluginContextMeta = Partial<RollupContextMeta> & ({
179179
} | {
180180
framework: 'esbuild'
181181
/** Set the host plugin name of esbuild when returning multiple plugins */
182-
esbuildHostName?: string
182+
esbuildHostName?: string | undefined
183183
} | {
184184
framework: 'rspack'
185185
rspack: { compiler: RspackCompiler }
186186
})
187187

188188
export interface UnpluginMessage {
189-
name?: string
190-
id?: string
189+
name?: string | undefined
190+
id?: string | undefined
191191
message: string
192-
stack?: string
193-
code?: string
194-
plugin?: string
195-
pluginCode?: unknown
192+
stack?: string | undefined
193+
code?: string | undefined
194+
plugin?: string | undefined
195+
pluginCode?: unknown | undefined
196196
loc?: {
197197
column: number
198-
file?: string
198+
file?: string | undefined
199199
line: number
200-
}
200+
} | undefined
201201
meta?: any
202202
}
203203

0 commit comments

Comments
 (0)