Skip to content

feat: add JSDoc type annotations and TypeScript type checking#21

Merged
tinsever merged 5 commits intov3-devfrom
feat/jsdoc-addition
Dec 31, 2025
Merged

feat: add JSDoc type annotations and TypeScript type checking#21
tinsever merged 5 commits intov3-devfrom
feat/jsdoc-addition

Conversation

@tinsever
Copy link
Owner

  • Add tsconfig.json with allowJs/checkJs for type checking without compilation
  • Add lib/types.d.ts with shared type definitions (FontData, FontResult, etc.)
  • Add lib/vendor.d.ts for untyped packages (copy-paste-win32fix, node-powershell)
  • Annotate all lib/*.js files with JSDoc type comments
  • Annotate cli.js with type annotations
  • Add typescript and @types/node devDependencies
  • Add 'typecheck' npm script

- Add tsconfig.json with allowJs/checkJs for type checking without compilation
- Add lib/types.d.ts with shared type definitions (FontData, FontResult, etc.)
- Add lib/vendor.d.ts for untyped packages (copy-paste-win32fix, node-powershell)
- Annotate all lib/*.js files with JSDoc type comments
- Annotate cli.js with type annotations
- Add typescript and @types/node devDependencies
- Add 'typecheck' npm script
Copy link

Copilot AI left a comment

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 adds comprehensive TypeScript type checking to a JavaScript codebase using JSDoc annotations and TypeScript's allowJs/checkJs options. The approach enables static type checking without requiring a full migration to TypeScript.

Key changes:

  • Added TypeScript tooling with a typecheck npm script for validation
  • Created comprehensive type definitions for internal types and untyped third-party packages
  • Annotated all library modules and the CLI with JSDoc type comments

Reviewed changes

Copilot reviewed 8 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tsconfig.json Configures TypeScript for JS type checking with appropriate compiler options
package.json Adds TypeScript and @types/node as dev dependencies, adds typecheck script
package-lock.json Lock file updates for new TypeScript dependencies
lib/vendor.d.ts Type declarations for untyped third-party packages (copy-paste-win32fix, node-powershell, pascal-case)
lib/types.d.ts Shared type definitions for font data structures, callbacks, and class instances
lib/system-font.js Adds JSDoc annotations for system font download/install operations
lib/request.js Adds JSDoc annotations for HTTP request handling
lib/noop.js Adds JSDoc annotation for default error callback
lib/google-font.js Adds JSDoc annotations for Google Font operations and methods
lib/google-font-list.js Adds JSDoc annotations for font list management and search operations
lib/cache.js Adds JSDoc annotations for cache read/write operations
cli.js Adds JSDoc annotations and @ts-check directive for CLI commands

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

/** @type {number} */
this.redirect = 3; // Allow up to 3 redirects
/** @type {boolean} */
this._fisrtBytes = false;
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

The typo in the property name "_fisrtBytes" should be "_firstBytes". This typo is copied from the type definition and should be corrected here as well.

Suggested change
this._fisrtBytes = false;
this._firstBytes = false;

Copilot uses AI. Check for mistakes.
* @param {URL} uri - Parsed URL object
* @returns {typeof http | typeof https} HTTP or HTTPS module
*/
Request.prototype._getProperLibray = function(uri){
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

The function name "_getProperLibray" contains a typo and should be "_getProperLibrary". While this is existing code, it would be good to fix the typo to improve code clarity.

Copilot uses AI. Check for mistakes.
} catch (e) {
var error = new Error('Failed to parse GWFH Fonts JSON: ' + e.message)
/** @type {Error & { isInvalidJson?: boolean }} */
var error = new Error('Failed to parse GWFH Fonts JSON: ' + /** @type {Error} */ (e).message)
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

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

Avoid automated semicolon insertion (91% of all statements in the enclosing function have an explicit semicolon).

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

tinsever and others added 3 commits January 1, 2026 00:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

Copilot AI commented Dec 31, 2025

@tinsever I've opened a new pull request, #22, to work on those changes. Once the pull request is ready, I'll request review from you.

[WIP] Address feedback on JSDoc type annotations
@tinsever tinsever merged commit a3b3027 into v3-dev Dec 31, 2025
@tinsever tinsever deleted the feat/jsdoc-addition branch January 1, 2026 17:47
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.

3 participants