解决方案:将 config\config.default.ts 末尾的
return { ...config, ...bizConfig, };
修改为
return { ...config as {}, ...bizConfig, };
自此,中间件中的配置参数便可以设置类型啦
import { Context, EggAppConfig } from 'egg'; import { appendFileSync } from 'fs'; export default (options: EggAppConfig) => { return async (ctx: Context, next: () => Promise<any>) => { const startTime = Date.now(); const requestTime = new Date(); await next(); const ms = Date.now() - startTime; const logTime = `${requestTime} -- ${ctx.method} --${ctx.url} -- ${ms}ms`; if (options.recordUrlList.includes(ctx.url)) { appendFileSync('./log.txt', logTime + '\n'); } }; };