diff --git a/lib/box/file.ts b/lib/box/file.ts index 70bccf1739..99bb509ddd 100644 --- a/lib/box/file.ts +++ b/lib/box/file.ts @@ -1,5 +1,6 @@ import type Promise from 'bluebird'; import { readFile, readFileSync, stat, statSync, type ReadFileOptions } from 'hexo-fs'; +import type fs from 'fs'; class File { public source: string; @@ -26,11 +27,11 @@ class File { return readFileSync(this.source, options); } - stat(): any { + stat(): Promise { return stat(this.source); } - statSync():any { + statSync(): fs.Stats { return statSync(this.source); } } diff --git a/lib/plugins/console/list/category.ts b/lib/plugins/console/list/category.ts index 819c6221dd..a1c6527c80 100644 --- a/lib/plugins/console/list/category.ts +++ b/lib/plugins/console/list/category.ts @@ -1,8 +1,9 @@ import { underline } from 'picocolors'; import table from 'text-table'; import { stringLength } from './common'; +import type Hexo from '../../../hexo'; -function listCategory(): void { +function listCategory(this: Hexo): void { const categories = this.model('Category'); const data = categories.sort({name: 1}).map(cate => [cate.name, String(cate.length)]); diff --git a/lib/plugins/console/list/page.ts b/lib/plugins/console/list/page.ts index aa6582b599..8b9de1bc09 100644 --- a/lib/plugins/console/list/page.ts +++ b/lib/plugins/console/list/page.ts @@ -1,8 +1,9 @@ import { magenta, underline, gray } from 'picocolors'; import table from 'text-table'; import { stringLength } from './common'; +import type Hexo from '../../../hexo'; -function listPage(): void { +function listPage(this: Hexo): void { const Page = this.model('Page'); const data = Page.sort({date: 1}).map(page => { diff --git a/lib/plugins/console/list/post.ts b/lib/plugins/console/list/post.ts index d893eeac04..280b339df8 100644 --- a/lib/plugins/console/list/post.ts +++ b/lib/plugins/console/list/post.ts @@ -1,12 +1,13 @@ import { gray, magenta, underline } from 'picocolors'; import table from 'text-table'; import { stringLength } from './common'; +import type Hexo from '../../../hexo'; function mapName(item) { return item.name; } -function listPost(): void { +function listPost(this: Hexo): void { const Post = this.model('Post'); const data = Post.sort({published: -1, date: 1}).map(post => { diff --git a/lib/plugins/console/list/route.ts b/lib/plugins/console/list/route.ts index f55cec3255..2c15e217cc 100644 --- a/lib/plugins/console/list/route.ts +++ b/lib/plugins/console/list/route.ts @@ -1,6 +1,7 @@ import archy from 'archy'; +import type Hexo from '../../../hexo'; -function listRoute(): void { +function listRoute(this: Hexo): void { const routes = this.route.list().sort(); const tree = buildTree(routes); const nodes = buildNodes(tree); diff --git a/lib/plugins/console/list/tag.ts b/lib/plugins/console/list/tag.ts index 258a0fd219..4ce37595d1 100644 --- a/lib/plugins/console/list/tag.ts +++ b/lib/plugins/console/list/tag.ts @@ -1,8 +1,9 @@ import { magenta, underline } from 'picocolors'; import table from 'text-table'; import { stringLength } from './common'; +import type Hexo from '../../../hexo'; -function listTag(): void { +function listTag(this: Hexo): void { const Tag = this.model('Tag'); const data = Tag.sort({name: 1}).map(tag => [tag.name, String(tag.length), magenta(tag.path)]); diff --git a/lib/plugins/processor/asset.ts b/lib/plugins/processor/asset.ts index 86a460502f..b4e364b0f8 100644 --- a/lib/plugins/processor/asset.ts +++ b/lib/plugins/processor/asset.ts @@ -6,6 +6,7 @@ import { Pattern } from 'hexo-util'; import { magenta } from 'picocolors'; import type { _File } from '../../box'; import type Hexo from '../../hexo'; +import type { Stats } from 'fs'; export = (ctx: Hexo) => { return { @@ -50,7 +51,7 @@ function processPage(ctx: Hexo, file: _File) { return Promise.all([ file.stat(), file.read() - ]).spread((stats, content) => { + ]).spread((stats: Stats, content: string | Buffer) => { const data = yfm(content); const output = ctx.render.getOutput(path); diff --git a/lib/plugins/processor/post.ts b/lib/plugins/processor/post.ts index 53e5438fce..7489a84021 100644 --- a/lib/plugins/processor/post.ts +++ b/lib/plugins/processor/post.ts @@ -7,6 +7,7 @@ import { slugize, Pattern, Permalink } from 'hexo-util'; import { magenta } from 'picocolors'; import type { _File } from '../../box'; import type Hexo from '../../hexo'; +import type { Stats } from 'fs'; const postDir = '_posts/'; const draftDir = '_drafts/'; @@ -88,7 +89,7 @@ function processPost(ctx: Hexo, file: _File) { return Promise.all([ file.stat(), file.read() - ]).spread((stats, content) => { + ]).spread((stats: Stats, content: string | Buffer) => { const data = yfm(content); const info = parseFilename(config.new_post_name, path); const keys = Object.keys(info);