Skip to content

Use JSDoc to clear types - #989

Open
wherewhere wants to merge 7 commits into
next-theme:masterfrom
wherewhere:jsdoc
Open

Use JSDoc to clear types#989
wherewhere wants to merge 7 commits into
next-theme:masterfrom
wherewhere:jsdoc

Conversation

@wherewhere

Copy link
Copy Markdown
Contributor

PR Checklist

  • The changes have been tested (for bug fixes / features).
  • Docs in NexT website have been added / updated (for features).

PR Type

  • Bugfix.
  • Feature.
  • Improvement.
  • Code style update (e.g. formatting, linting).
  • Refactoring (no changes to functionality and APIs).
  • Documentation.
  • Translation.
  • Other... Please describe:

Issue resolved: #954

Todo List

  • Add types for scripts
  • Add types for source

@wherewhere

Copy link
Copy Markdown
Contributor Author

I see


group and layout is string, but
dispatch(pictures, group, layout) {
const rule = LAYOUTS[group] ? LAYOUTS[group][layout] : null;

templates.dispatch needs number. Is that correct?

@wherewhere
wherewhere marked this pull request as ready for review August 5, 2026 12:30
Copilot AI lite review requested due to automatic review settings August 5, 2026 12:30
@wherewhere

Copy link
Copy Markdown
Contributor Author

Some of the type define maybe ugly...

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #954 by improving JavaScript type clarity across the NexT theme via JSDoc annotations, TS declaration files, and triple-slash reference directives so editors/type-checkers can infer types instead of falling back to any.

Changes:

  • Added extensive JSDoc annotations to source/js and scripts/ code to improve inferred types.
  • Introduced source/js/config.d.ts and source/js/pjax.d.ts, and wired them via /// <reference ... />.
  • Updated devDependencies to support the new typing approach (e.g., @next-theme/pjax, @types/*).

Reviewed changes

Copilot reviewed 58 out of 60 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
source/js/utils.js Adds JSDoc types for utilities
source/js/third-party/tags/wavedrom.js Adds utils reference for typing
source/js/third-party/tags/pdf.js Adds utils reference for typing
source/js/third-party/tags/mermaid.js Adds utils reference for typing
source/js/third-party/statistics/lean-analytics.js Adds config reference + JSDoc
source/js/third-party/statistics/firestore.js Adds JSDoc for helpers
source/js/third-party/search/local-search.js Adds search-result typedefs
source/js/third-party/search/algolia-search.js Adds config typing annotations
source/js/third-party/quicklink.js Adds config reference + types
source/js/third-party/math/mathjax.js Adds utils reference for typing
source/js/third-party/math/katex.js Adds utils reference for typing
source/js/third-party/comments/utterances.js Adds utils reference for typing
source/js/third-party/comments/livere.js Adds utils reference for typing
source/js/third-party/comments/isso.js Adds utils reference for typing
source/js/third-party/comments/gitalk.js Adds utils reference for typing
source/js/third-party/comments/disqusjs.js Adds utils reference for typing
source/js/third-party/comments/disqus.js Adds utils reference for typing
source/js/third-party/comments/changyan.js Adds config typing annotations
source/js/third-party/chat/chatra.js Adds config reference for typing
source/js/third-party/analytics/matomo.js Adds config reference for typing
source/js/third-party/analytics/growingio.js Adds deprecation tag + config ref
source/js/third-party/analytics/google-analytics.js Adds config reference for typing
source/js/third-party/addtoany.js Adds utils reference for typing
source/js/sidebar.js Adds config reference for typing
source/js/schedule.js Adds calendar typing annotations
source/js/pjax.js Adds references for pjax types
source/js/pjax.d.ts Declares global Pjax typings
source/js/next-boot.js Adds motion reference for typing
source/js/motion.js Adds motion sequence typedefs
source/js/config.js Adds references + typed helpers
source/js/config.d.ts Declares global CONFIG shape
source/js/comments.js Adds config reference for typing
source/js/comments-buttons.js Adds config reference for typing
source/js/bookmark.js Adds utils reference + JSDoc
scripts/tags/wavedrom.js Adds JSDoc param typing
scripts/tags/video.js Adds JSDoc param typing
scripts/tags/tabs.js Adds ctx/args/content typings
scripts/tags/pdf.js Adds ctx/args typings
scripts/tags/note.js Adds args/content typings
scripts/tags/mermaid.js Adds args/content typings
scripts/tags/link-grid.js Adds content typing
scripts/tags/label.js Adds ctx/args typing
scripts/tags/group-pictures.js Adds JSDoc for helpers/types
scripts/tags/center-quote.js Adds content typing
scripts/tags/caniuse.js Adds ctx/args typing
scripts/tags/button.js Adds ctx/args typing
scripts/helpers/next-vendors.js Adds vendors array typing
scripts/helpers/next-url.js Adds JSDoc typing block
scripts/helpers/navigation.js Adds TreeNode typing for menu helper
scripts/helpers/font.js Adds font config typings
scripts/helpers/engine.js Adds helper parameter typings
scripts/filters/minify.js Removes emitted .d.ts when minifying
scripts/filters/comment/common.js Adds typing for helper funcs
scripts/events/lib/vendors.js Adds hexo param typing
scripts/events/lib/utils.js Adds typings for css parsing helpers
scripts/events/lib/navigation.js Adds typing for menu tree builder
scripts/events/lib/injects.js Adds typing for inject managers
scripts/events/lib/highlight.js Adds typing for theme resolution
scripts/events/lib/config.js Adds hexo param typing
package.json Adds typing-related dev deps
Suppressed comments (1)

source/js/third-party/search/local-search.js:33

  • This annotation still references the misspelled ReasultItem typedef. Update it to ResultItem[] after renaming the typedef.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +4 to +11
/**
* @typedef {{
* item: string,
* id: number,
* hitCount: number,
* includedCount: number
* }} ReasultItem
*/
Comment on lines +14 to 17
/**
* @param {string} name
*/
function resolve(name, file = '') {
Comment on lines +8 to +13
/**
* @param {string} path
* @param {string} text
* @param {Record<string, string>} options
*/
= function(path, text, options = {}, decode = false) {
Comment thread source/js/config.js Outdated
Comment on lines 22 to 24
/** @type {HTMLScriptElement} */
const targetEle = document.querySelector(`.${className}[data-name="${name}"]`);
if (!targetEle) return;
Comment thread source/js/schedule.js Outdated
Comment on lines 7 to 8
/** @type {typeof CONFIG.calendar} */
const calendar = {
Comment on lines +5 to +8
/**
* @typedef {import('../events/lib/navigation.js').TreeNode} TreeNode
*/

const fs = require('fs');
const path = require('path');

/** @type {typeof import('@types/css')} */
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 31036603352

Coverage increased (+0.7%) to 88.708%

Details

  • Coverage increased (+0.7%) from the base build.
  • Patch coverage: 115 of 115 lines across 15 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 665
Covered Lines: 587
Line Coverage: 88.27%
Relevant Branches: 132
Covered Branches: 120
Branch Coverage: 90.91%
Branches in Coverage %: Yes
Coverage Strength: 2.85 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use JSDoc to clear types

4 participants