Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor types #5178

Merged
merged 6 commits into from Apr 20, 2023
Merged

Refactor types #5178

merged 6 commits into from Apr 20, 2023

Conversation

Pcrab
Copy link
Contributor

@Pcrab Pcrab commented Mar 27, 2023

What does it do?

Add types to Hexo class and extend apis.

Only types are changed except for lib/extend/tag.ts, where I added an intermediate variable. All these changes should have no effect on runtime behavior.

This may help plugin authors who can now add hexo as devdependency and add declare var hexo: import("hexo") to global.d.ts to get better type inference.

Screenshots

After adds

image

I can get better type inference like this:

image

which used to be just any type.

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@github-actions
Copy link

How to test

git clone -b refactor-types https://github.com/Pcrab/hexo.git
cd hexo
npm install
npm test

@coveralls
Copy link

Coverage Status

Coverage: 98.669% (+0.03%) from 98.635% when pulling 4c99a3d on Pcrab:refactor-types into 46fbdcf on hexojs:v7.0.0.

@@ -1,4 +1,6 @@
export = function(ctx) {
import Hexo from '../../hexo';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import Hexo from '../../hexo';
import type Hexo from '../../hexo';

Use import type for type only imports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3ad806d.

Maybe we should add a rule in .eslintrc.json to enforce this style?

{
  "rules": {
    "@typescript-eslint/consistent-type-imports": "warn",
  }
}

Copy link
Member

@yoshinorin yoshinorin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :)

@yoshinorin yoshinorin merged commit 725422a into hexojs:v7.0.0 Apr 20, 2023
2 of 9 checks passed
@yoshinorin yoshinorin added this to the 7.0.0 milestone Apr 20, 2023
@Pcrab Pcrab deleted the refactor-types branch April 21, 2023 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants