feat: add JSDoc type annotations and TypeScript type checking#21
feat: add JSDoc type annotations and TypeScript type checking#21
Conversation
tinsever
commented
Dec 31, 2025
- 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
There was a problem hiding this comment.
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
typechecknpm 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; |
There was a problem hiding this comment.
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.
| this._fisrtBytes = false; | |
| this._firstBytes = false; |
| * @param {URL} uri - Parsed URL object | ||
| * @returns {typeof http | typeof https} HTTP or HTTPS module | ||
| */ | ||
| Request.prototype._getProperLibray = function(uri){ |
There was a problem hiding this comment.
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.
| } 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) |
There was a problem hiding this comment.
Avoid automated semicolon insertion (91% of all statements in the enclosing function have an explicit semicolon).
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
[WIP] Address feedback on JSDoc type annotations