hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
38.83k stars 4.75k forks source link

fix(types): cast from `number` to `string` explicitly #5342

Closed yoshinorin closed 8 months ago

yoshinorin commented 8 months ago

What does it do?

fix TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. error. I ignore them with @ts-ignore when I published v7.0.0.

$ npm run build

> hexo@7.0.0 build
> tsc -b

lib/hexo/multi_config_path.ts:65:28 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

65   log.i('Config based on', count, 'files');
                              ~~~~~

lib/plugins/console/generate.ts:172:44 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

172       log.info('%d files generated in %s', count, cyan(interval));
                                               ~~~~~
Found 2 errors.

Screenshots

N/A

Pull request tasks

github-actions[bot] commented 8 months ago

Publish flamegraph to https://98a38e86ecc0f039a07dece2e29f0dcaaffc98fa-16-hexo.surge.sh/flamegraph.html

coveralls commented 8 months ago

Pull Request Test Coverage Report for Build 6709541831


Totals Coverage Status
Change from base Build 6707257857: 0.0%
Covered Lines: 8997
Relevant Lines: 9039

💛 - Coveralls
uiolee commented 8 months ago

what circumstances does this problem occur. I can't reproduce it.

yoshinorin commented 8 months ago

@uiolee

what circumstances does this problem occur. I can't reproduce it.

Checkout master branch and just run npm run build.

// My local env
$ systeminfo
OS Name:                  Microsoft Windows 11 Pro
OS Version:               10.0.22621 N/A Build 22621

$ node -v
v20.5.1

$  tsc -v
Version 4.6.4
// chekout master branch
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'upstream/master'.

$ git branch -v --contains 
* master         f7a581ea release: v7.0.0 (#5329)

// just run build command
$ npm run build                                

> hexo@7.0.0 build
> tsc -b

lib/hexo/multi_config_path.ts:65:28 - error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

65   log.i('Config based on', count, 'files');
``
uiolee commented 8 months ago

I try node@20.5.1 and still can't reproduce. But found more issue on tsc@4.6.4

tsc 4.6.4

```bash $ npx tsc -v Version 4.6.4 $ npm run build > hexo@7.0.0 build > tsc -b lib/box/index.ts:60:3 - error TS4055: Return type of public method from exported class has or is using private name '_File'. 60 _createFileClass() { ~~~~~~~~~~~~~~~~ lib/hexo/index.ts:463:3 - error TS4055: Return type of public method from exported class has or is using private name 'Locals'. 463 _generateLocals() { ~~~~~~~~~~~~~~~ lib/hexo/router.ts:17:27 - error TS4020: 'extends' clause of exported class 'RouteStream' has or is using private name 'Readable'. 17 class RouteStream extends Readable { ~~~~~~~~ Found 3 errors. ```

D-Sketon commented 8 months ago

v4.6.4 found 3 errors v4.9.5 found 0 error

yoshinorin commented 8 months ago

v4.6.4 found 3 errors v4.9.5 found 0 error

Can we specify which version of tsc to use in package.json or other files?

uiolee commented 8 months ago

I think we can follow the latest version