From 46c48092c966b4fd8e25b791547c3c6e3c9be1a2 Mon Sep 17 00:00:00 2001 From: D-Sketon <2055272094@qq.com> Date: Tue, 14 Nov 2023 23:18:51 +0800 Subject: [PATCH] fix types --- lib/box/index.ts | 2 +- lib/extend/renderer.ts | 2 +- lib/hexo/index.ts | 2 +- lib/hexo/load_config.ts | 2 +- lib/hexo/render.ts | 6 +++--- lib/hexo/scaffold.ts | 4 ++-- lib/plugins/console/config.ts | 1 + lib/plugins/console/deploy.ts | 3 ++- lib/plugins/console/generate.ts | 1 + lib/plugins/console/migrate.ts | 1 + lib/plugins/console/new.ts | 1 + lib/plugins/console/publish.ts | 1 + lib/plugins/console/render.ts | 1 + 13 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/box/index.ts b/lib/box/index.ts index cd0243a274..e55079c8de 100644 --- a/lib/box/index.ts +++ b/lib/box/index.ts @@ -13,7 +13,7 @@ const defaultPattern = new Pattern(() => ({})); interface Processor { pattern: Pattern; - process: (file: File) => void; + process: (file?: File) => any; } class Box extends EventEmitter { diff --git a/lib/extend/renderer.ts b/lib/extend/renderer.ts index f966a67fd0..5a0d03abf3 100644 --- a/lib/extend/renderer.ts +++ b/lib/extend/renderer.ts @@ -14,7 +14,7 @@ export interface StoreFunctionData { text?: string; engine?: string; toString?: any; - onRenderEnd?: any; + onRenderEnd?: (...args: any[]) => any; } export interface StoreSyncFunction { diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index a7dd75df18..8fd4f32c55 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -7,7 +7,7 @@ import { EventEmitter } from 'events'; import { readFile } from 'hexo-fs'; import Module from 'module'; import { runInThisContext } from 'vm'; -const {version} = require('../../package.json'); +const { version } = require('../../package.json'); import logger from 'hexo-log'; import { diff --git a/lib/hexo/load_config.ts b/lib/hexo/load_config.ts index 49ed3ba3ef..009aa4587c 100644 --- a/lib/hexo/load_config.ts +++ b/lib/hexo/load_config.ts @@ -53,7 +53,7 @@ export = async (ctx: Hexo): Promise => { const themeDirFromNodeModules = join(ctx.plugin_dir, 'hexo-theme-' + theme) + sep; // base_dir/node_modules/hexo-theme-[config.theme]/ // themeDirFromThemes has higher priority than themeDirFromNodeModules - let ignored = []; + let ignored: string[] = []; if (await exists(themeDirFromThemes)) { ctx.theme_dir = themeDirFromThemes; ignored = ['**/themes/*/node_modules/**', '**/themes/*/.git/**']; diff --git a/lib/hexo/render.ts b/lib/hexo/render.ts index 7a0240c567..91ce8e01ff 100644 --- a/lib/hexo/render.ts +++ b/lib/hexo/render.ts @@ -65,7 +65,7 @@ class Render { const ctx = this.context; let ext = ''; - let promise: Promise; + let promise: Promise; if (!data) return Promise.reject(new TypeError('No input file or string!')); @@ -74,10 +74,10 @@ class Render { } else if (!data.path) { return Promise.reject(new TypeError('No input file or string!')); } else { - promise = readFile(data.path); + promise = readFile(data.path) as Promise; } - return promise.then((text: string) => { + return promise.then(text => { data.text = text; ext = data.engine || getExtname(data.path); if (!ext || !this.isRenderable(ext)) return text; diff --git a/lib/hexo/scaffold.ts b/lib/hexo/scaffold.ts index 9f44137114..8b97c6305f 100644 --- a/lib/hexo/scaffold.ts +++ b/lib/hexo/scaffold.ts @@ -61,7 +61,7 @@ class Scaffold { }).asCallback(callback); } - set(name: string, content: any, callback: NodeJSLikeCallback): Promise { + set(name: string, content: any, callback?: NodeJSLikeCallback): Promise { const { scaffoldDir } = this; return this._getScaffold(name).then(item => { @@ -72,7 +72,7 @@ class Scaffold { }).asCallback(callback); } - remove(name: string, callback: NodeJSLikeCallback): Promise { + remove(name: string, callback?: NodeJSLikeCallback): Promise { return this._getScaffold(name).then(item => { if (!item) return; diff --git a/lib/plugins/console/config.ts b/lib/plugins/console/config.ts index 6fdf77c1e5..c46f9793f3 100644 --- a/lib/plugins/console/config.ts +++ b/lib/plugins/console/config.ts @@ -6,6 +6,7 @@ import type Hexo from '../../hexo'; interface ConfigArgs { _: string[] + [key: string]: any } function configConsole(this: Hexo, args: ConfigArgs): Promise { diff --git a/lib/plugins/console/deploy.ts b/lib/plugins/console/deploy.ts index 99a36c4bf4..811be33b48 100644 --- a/lib/plugins/console/deploy.ts +++ b/lib/plugins/console/deploy.ts @@ -3,9 +3,10 @@ import { underline, magenta } from 'picocolors'; import type Hexo from '../../hexo'; interface DeployArgs { - _: string[] + _?: string[] g?: boolean generate?: boolean + [key: string]: any } function deployConsole(this: Hexo, args: DeployArgs) { diff --git a/lib/plugins/console/generate.ts b/lib/plugins/console/generate.ts index 5864cd7ad3..721a9e8539 100644 --- a/lib/plugins/console/generate.ts +++ b/lib/plugins/console/generate.ts @@ -19,6 +19,7 @@ interface GenerateArgs { watch?: boolean d?: boolean deploy?: boolean + [key: string]: any } class Generater { diff --git a/lib/plugins/console/migrate.ts b/lib/plugins/console/migrate.ts index f1fdca5c15..d6b3ad3e47 100644 --- a/lib/plugins/console/migrate.ts +++ b/lib/plugins/console/migrate.ts @@ -3,6 +3,7 @@ import type Hexo from '../../hexo'; interface MigrateArgs { _: string[] + [key: string]: any } function migrateConsole(this: Hexo, args: MigrateArgs) { diff --git a/lib/plugins/console/new.ts b/lib/plugins/console/new.ts index 1000a82e21..2b48b77b11 100644 --- a/lib/plugins/console/new.ts +++ b/lib/plugins/console/new.ts @@ -28,6 +28,7 @@ interface NewArgs { slug?: string r?: boolean replace?: boolean + [key: string]: any } function newConsole(this: Hexo, args: NewArgs) { diff --git a/lib/plugins/console/publish.ts b/lib/plugins/console/publish.ts index 6f5a9abcd4..38913e8316 100644 --- a/lib/plugins/console/publish.ts +++ b/lib/plugins/console/publish.ts @@ -6,6 +6,7 @@ interface PublishArgs { _: string[] r?: boolean replace?: boolean + [key: string]: any } function publishConsole(this: Hexo, args: PublishArgs) { diff --git a/lib/plugins/console/render.ts b/lib/plugins/console/render.ts index 98abf4bf11..68cb95a710 100644 --- a/lib/plugins/console/render.ts +++ b/lib/plugins/console/render.ts @@ -11,6 +11,7 @@ interface RenderArgs { output?: string pretty?: boolean engine?: string + [key: string]: any } function renderConsole(this: Hexo, args: RenderArgs) {