Open
Conversation
Rename every source file under src/ from .js to .ts and wire up a TypeScript toolchain. This is a "loose" conversion: each file has `// @ts-nocheck` at the top so the existing dynamic-JavaScript patterns (untyped class fields, implicit any, etc.) keep working unchanged. Types can be added incrementally from here. - Rename src/**/*.js → *.ts and update imports to use .ts extensions (required by Node's --experimental-strip-types resolver). - Update tsconfig.json: target es2022, module/moduleResolution nodenext, allowImportingTsExtensions, noEmit, loose strictness. - Switch webpack from ./src/index.js to ./src/index.ts and use ts-loader with transpileOnly. Drop eslint-webpack-plugin (was only checking .js). - Tests stay as .js but import .ts sources directly; `npm test` now runs `node --experimental-strip-types --test ...`. - Delete the manually maintained .d.ts files (src/*.d.ts, index.d.ts) and the typedefs.spec.js test that verified them — TypeScript now enforces the contract directly. - Update bench.js, CLAUDE.md, README.md, and package.json (description, exports, files, scripts) to reflect the TypeScript layout. All 577 tests pass; `npm run build` produces dist/jsnes.js and dist/jsnes.min.js as before.
Remove `@ts-nocheck` from the exported classes (NES, Controller, Browser, GameGenie) and add real type annotations to the surface that consumers see. The internal emulator modules (CPU, PPU, PAPU, mappers, browser helpers) still have `@ts-nocheck` — references to them from the public classes are typed as `any` so the implementation keeps working unchanged. Public types exported from `src/index.ts`: - `NESOptions`, `EmulatorData`, `ControllerId`, `RomData` - `ButtonKey`, `ControllerState` - `BrowserOptions` - `GameGeniePatch` The class fields, method parameters, and return types on the exported classes themselves are also annotated so consumers get IntelliSense on things like `nes.loadROM(...)`, `controller.buttonDown(...)`, etc. All 577 tests still pass and the webpack build is unchanged.
08b8511 to
7ab1e5b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR converts the JSNES codebase from JavaScript to TypeScript, enabling better type safety and IDE support while maintaining backward compatibility. The conversion uses a "loose" approach with
@ts-nocheckon most files to allow existing JavaScript patterns to continue working, with types added incrementally to the public API surface.Key Changes
.jsfiles insrc/renamed to.tswith updated import statements to use.tsextensions.d.tsdeclaration files (nes.d.ts,controller.d.ts,browser.d.ts,gamegenie.d.ts) and integrated types directly into.tssource filesNESclass:NESOptions,RomData,ControllerId,EmulatorDataControllerclass:ButtonKey,ControllerStatetypes and readonly static membersBrowserclass:BrowserOptionsinterfaceGameGenieclass:GameGeniePatchinterfacets-loaderwithtranspileOnly: truefor bundling TypeScript sourcetsconfig.jsonto target ES2022, usenodenextmodule resolution, and allow importing.tsextensions.jsfiles but now import.tssource files directly; removedtypedefs.spec.jstest file (no longer needed with integrated types).tssource for ESM imports; removed separateindex.d.tsfileImplementation Details
// @ts-nocheckto allow loose JavaScript patterns during the conversion phaseNES,Controller,Browser,GameGenie) have full type annotations for method signatures and properties.tsextensions (e.g.,import CPU from "./cpu.ts") to work with Node.js--experimental-strip-typesdist/jsnes.js,dist/jsnes.min.js) remains JavaScript for browser compatibilitytsc --noEmitvalidates the public API surfacehttps://claude.ai/code/session_019TZShVDgaieoXF4hnbEgXb