Skip to content

Migrate to TypeScript#35

Merged
willeastcott merged 9 commits intomainfrom
typescript
Jan 6, 2026
Merged

Migrate to TypeScript#35
willeastcott merged 9 commits intomainfrom
typescript

Conversation

@willeastcott
Copy link
Contributor

@willeastcott willeastcott commented Jan 5, 2026

This pull request migrates the codebase from JavaScript to TypeScript, enhances type safety, and improves the build and linting setup. It removes the old copy-and-watch.mjs plugin, introduces a new TypeScript-compatible version under plugins/, updates the Rollup and ESLint configurations for TypeScript support, and refactors source files to use explicit types and interfaces. Several dependencies are updated or added to support these changes.

Build and Tooling Improvements:

  • Replaces the old copy-and-watch.mjs with a new, TypeScript-compatible version in plugins/copy-and-watch.mjs, and updates the usage in rollup.config.mjs to use the new plugin and a shared TARGETS array. [1] [2] [3] [4] [5]
  • Adds @rollup/plugin-typescript and updates the Rollup config to use src/index.ts as the entry point, enabling TypeScript compilation. [1] [2] [3] [4]
  • Updates and extends ESLint configuration to support TypeScript files, including custom rules and TypeScript parser/plugin integration. [1] [2] [3]

Source Code Refactoring to TypeScript:

  • Renames source files from .js to .ts and adds type annotations, interfaces, and type imports throughout the codebase for improved type safety (e.g., src/const.ts, src/drop-handler.ts, src/export-panel.ts, src/feedback-panel.ts, src/file-tabs.ts). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]

Dependency Updates:

  • Adds and updates dependencies related to TypeScript (typescript, tslib, @typescript-eslint/*, eslint-import-resolver-typescript, etc.) and bumps rollup to the latest version.

These changes collectively modernize the codebase, streamline the build process, and improve maintainability and type safety.

@willeastcott willeastcott self-assigned this Jan 5, 2026
@willeastcott willeastcott added the enhancement New feature or request label Jan 5, 2026
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 migrates the texture tool project from JavaScript to TypeScript, adding comprehensive type safety throughout the codebase. The migration also includes build system updates to support TypeScript compilation, ESLint configuration for TypeScript files, and several bug fixes discovered during the type annotation process.

Key changes:

  • Complete migration of all source files from .js to .ts with type annotations
  • Addition of TypeScript compiler configuration and build tooling
  • ESLint configuration extended to support TypeScript linting
  • Several bug fixes identified and corrected during migration (including API usage fixes, typo corrections, and type consistency improvements)

Reviewed changes

Copilot reviewed 27 out of 30 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tsconfig.json New TypeScript compiler configuration with ES2022 target and strict type checking options
src/**/*.ts All source files migrated to TypeScript with comprehensive type annotations for classes, methods, parameters, and return types
src/declaration.d.ts New type declarations for File System Access API and browser extensions
rollup.config.mjs Updated to use TypeScript plugin and refactored copy-and-watch plugin configuration
plugins/copy-and-watch.mjs Refactored Rollup plugin moved to dedicated plugins directory with improved structure
eslint.config.mjs Extended ESLint configuration to support TypeScript with appropriate parser and plugins
package.json Added TypeScript dependencies and tooling (@typescript-eslint packages, TypeScript 5.9.3)
copy-and-watch.mjs Original plugin file removed (moved to plugins/ directory)
src/texture-doc.js Removed (replaced by src/texture-doc.ts)
Comments suppressed due to low confidence (11)

src/reproject-panel.ts:207

  • The change from accessing 'format[targetEncoding]' instead of assigning 'format' directly is a bug fix. The original code would have assigned the entire format object to the texture format property instead of looking up the specific format value for the target encoding.
    src/export-panel.ts:34
  • The change from 'data.buffer' to wrapping the data in a Blob fixes a potential issue. The original code passed a Uint8Array directly, but the Blob constructor expects an array of buffer sources. While both might work in some browsers, wrapping the data properly is more correct.
    src/reproject-panel.ts:224
  • Fixed spacing inconsistency. The default case now has consistent spacing with other cases in the switch statement (removed extra space before 't.type').
    src/files-browser-panel.ts:371
  • The trailing space after 'ui.selected' has been removed, improving code cleanliness and consistency.
    src/texture-view.ts:67
  • The property name 'opaqueSortMode' appears to be correct, but the original code had 'opaqueSortMost' which looks like a typo. However, this change is in the middle of a TypeScript migration and appears to be fixing a bug rather than introducing one. The correct property name for the Layer constructor should be 'opaqueSortMode' based on the PlayCanvas engine API.
    src/texture-view.ts:140
  • The change from 'Uint8ClampedArray' to 'Uint8Array' changes the behavior of array element clamping. Uint8ClampedArray automatically clamps values to the 0-255 range, while Uint8Array wraps values using modulo arithmetic. For creating a default texture with fixed values [64, 64, 64, 255], this change is safe, but it's worth noting this behavioral difference.
    src/reproject-panel.ts:200
  • The variable name 'typeMap' is more descriptive and accurate than 'type' since it's a mapping object rather than a single type value. This is an improvement in code clarity and naming convention.
    src/texture-manager.ts:66
  • The AssetRegistry.remove() method expects an Asset object as a parameter, not an ID number. The change from 'this.assets.remove(id)' to 'this.assets.remove(asset)' is a bug fix that corrects the API usage.
    src/render-canvas.ts:49
  • Fixed typo in CSS style property. The original code had 'py' instead of 'px' for the height unit, which would cause incorrect styling. This is a bug fix rather than an introduction of a new bug.
    src/reproject-panel.ts:154
  • The value should be a string '2' instead of a number 2, based on the type inference from the encoding variable which uses string values elsewhere. This change appears to be a bug fix ensuring type consistency.
    src/reproject-panel.ts:285
  • The removed function 'generateEnvAtlas' was never implemented (it had an empty body) and was not being called anywhere in the codebase. This is a cleanup of dead code during the TypeScript migration.

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

@willeastcott willeastcott merged commit 17ae7f1 into main Jan 6, 2026
2 checks passed
@willeastcott willeastcott deleted the typescript branch January 6, 2026 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants