From d785b9f2268ef6c656b37a641d6a9a591a736e00 Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 5 Nov 2025 21:03:29 +0800 Subject: [PATCH] refactor: replace any type with unknown in type definitions --- e2e/helper/logs.ts | 2 +- packages/plugin-less/src/index.ts | 2 +- packages/plugin-react/src/splitChunks.ts | 2 +- packages/plugin-sass/src/helpers.ts | 28 +++++++++++++++--------- packages/plugin-svelte/src/index.ts | 4 ++-- packages/plugin-vue/src/splitChunks.ts | 2 +- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/e2e/helper/logs.ts b/e2e/helper/logs.ts index be10fcfe59..ad01a8d939 100644 --- a/e2e/helper/logs.ts +++ b/e2e/helper/logs.ts @@ -148,7 +148,7 @@ export const proxyConsole = ({ restores.push(() => { console[type] = method; }); - console[type] = (...args: any[]) => { + console[type] = (...args: unknown[]) => { const logMessage = args .map((arg) => { if (typeof arg === 'string') { diff --git a/packages/plugin-less/src/index.ts b/packages/plugin-less/src/index.ts index 81a1d3ccd2..a58a11ad0c 100644 --- a/packages/plugin-less/src/index.ts +++ b/packages/plugin-less/src/index.ts @@ -11,7 +11,7 @@ import { reduceConfigsWithContext } from 'reduce-configs'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); -export const isPlainObject = (obj: unknown): obj is Record => { +export const isPlainObject = (obj: unknown): obj is Record => { return ( obj !== null && typeof obj === 'object' && diff --git a/packages/plugin-react/src/splitChunks.ts b/packages/plugin-react/src/splitChunks.ts index 68655b9d5a..dcc68ba660 100644 --- a/packages/plugin-react/src/splitChunks.ts +++ b/packages/plugin-react/src/splitChunks.ts @@ -1,7 +1,7 @@ import type { RsbuildPluginAPI, Rspack } from '@rsbuild/core'; import type { SplitReactChunkOptions } from './index.js'; -const isPlainObject = (obj: unknown): obj is Record => +const isPlainObject = (obj: unknown): obj is Record => obj !== null && typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]'; diff --git a/packages/plugin-sass/src/helpers.ts b/packages/plugin-sass/src/helpers.ts index f986722751..c2db84d55b 100644 --- a/packages/plugin-sass/src/helpers.ts +++ b/packages/plugin-sass/src/helpers.ts @@ -26,9 +26,10 @@ function unpatchGlobalLocation() { } } -type CompilerTapFn void = () => void> = { - tap: (name: string, cb: CallBack) => void; -}; +type CompilerTapFn void = () => void> = + { + tap: (name: string, cb: CallBack) => void; + }; export function patchCompilerGlobalLocation(compiler: { hooks: { @@ -45,6 +46,11 @@ export function patchCompilerGlobalLocation(compiler: { compiler.hooks.done.tap('PatchGlobalLocation', unpatchGlobalLocation); } +type ResolveUrlJoinItem = { + uri: string; + [key: string]: unknown; +}; + /** * fix resolve-url-loader can't deal with resolve.alias config * @@ -58,13 +64,15 @@ export const getResolveUrlJoinFn = (): ((...args: unknown[]) => void) => { defaultJoinGenerator, } = resolveUrlHelpers; - const rsbuildGenerator = asGenerator((item: any, ...rest: any[]) => { - // only handle relative path (not absolutely accurate, but can meet common scenarios) - if (!item.uri.startsWith('.')) { - return [null]; - } - return defaultJoinGenerator(item, ...rest); - }); + const rsbuildGenerator = asGenerator( + (item: ResolveUrlJoinItem, ...rest: unknown[]) => { + // only handle relative path (not absolutely accurate, but can meet common scenarios) + if (!item.uri.startsWith('.')) { + return [null]; + } + return defaultJoinGenerator(item, ...rest); + }, + ); return createJoinFunction( 'rsbuild-resolve-join-fn', createJoinImplementation(rsbuildGenerator), diff --git a/packages/plugin-svelte/src/index.ts b/packages/plugin-svelte/src/index.ts index 487ff5c99b..4d84a2ff03 100644 --- a/packages/plugin-svelte/src/index.ts +++ b/packages/plugin-svelte/src/index.ts @@ -21,9 +21,9 @@ export interface SvelteLoaderOptions { hotOptions?: { /** Preserve local component state */ preserveLocalState?: boolean; - [key: string]: any; + [key: string]: unknown; }; - [key: string]: any; + [key: string]: unknown; } export type PluginSvelteOptions = { diff --git a/packages/plugin-vue/src/splitChunks.ts b/packages/plugin-vue/src/splitChunks.ts index f63a26aaf9..f4aa016a51 100644 --- a/packages/plugin-vue/src/splitChunks.ts +++ b/packages/plugin-vue/src/splitChunks.ts @@ -1,7 +1,7 @@ import type { RsbuildPluginAPI, Rspack } from '@rsbuild/core'; import type { SplitVueChunkOptions } from './index.js'; -const isPlainObject = (obj: unknown): obj is Record => +const isPlainObject = (obj: unknown): obj is Record => obj !== null && typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]';