Skip to content

Convert codebase to TypeScript#24

Open
Mearman wants to merge 49 commits intopebble-dev:mainfrom
Mearman:typescript
Open

Convert codebase to TypeScript#24
Mearman wants to merge 49 commits intopebble-dev:mainfrom
Mearman:typescript

Conversation

@Mearman
Copy link
Copy Markdown

@Mearman Mearman commented Apr 19, 2026

Full TypeScript conversion of all source, components, entry points, and tests.
If accepted, would supersede #23.

Mearman added 30 commits April 19, 2026 09:46
Provide TypeScript ambient declarations for 'message_keys' (Pebble SDK
module) and './tmp/config-page.html' (build artefact) so tsc can resolve
these imports when generating .d.ts files.
Configures tsc --allowJs --emitDeclarationOnly to generate per-file
.d.ts reference output in dist-types/ from the library source files.
Hand-curated index.d.ts covering Clay, ClayConfig, ClayItem, ClayEvents,
manipulators, and all supporting types. Necessary because tsc cannot
infer the ClayEvents mixin or dynamically-bound manipulator methods.
All types are exported via the Clay namespace.
Exercises the full public API surface — constructor, instance/static
methods, ClayConfig/ClayItem event methods, manipulator methods,
namespace-exported types, and customFn this-context.
Adds typescript 6.0.2 as a devDependency. Sets "types": "index.d.ts"
in package.json. Adds build:types and check:types scripts.
Validates index.d.ts against test/type-checks.ts as part of the default
gulp build. Reference declaration generation via build:types remains
available as a separate manual step.
Add dist-types/ to .gitignore (build artefact). Whitelist index.d.ts
in .npmignore so type declarations ship with the package.
Runs npm run check:types on push and PR to main, matching the existing
lint/test/build workflow pattern.
Add tsconfig.json (type-checking via tsc --noEmit) and tsconfig.build.json
(declaration generation). Integrate tsify into browserify for both gulp
and karma. Add type stubs for vendored minified.js and .tpl templates.
Install @types/chai, @types/sinon, @types/mocha, and tsify.
Add ActiveWatchInfo and CapabilityMapping interfaces. Type all function
parameters and return values. Use export = for CommonJS compatibility.
Type the registry as Record<string, ClayComponent> with interfaces for
ClayComponent and ClayComponentManipulator.
Type the event mixin constructor, proxy registry, and on/off/trigger
methods. Use import = require for minified.js dependency.
Define ManipulatorContext and Manipulator interfaces. Type all get/set
and shared disable/enable/hide/show methods with explicit this parameter.
- Use ES6 import syntax for all dependencies
- Add ClayConfigItem interface for config parameter
- Type function context as `this: any` for mixin pattern
- Remove redundant JSDoc annotations
- Use const instead of var
- Update comments to British English spelling (initialiser)
Update minified.d.ts stub to use a generic constraint instead of
Record<string, T>, removing the need for type assertions at call sites.
Type constructor parameters, private functions, instance methods, and
static registerComponent. Define ClayConfigItem and ClayMeta interfaces.
Use as const for EVENTS string literals.
Check typeof method === 'function' before calling bind, satisfying
the stricter eachObj callback type.
Replace unsafe any and as type assertions with proper typing:
- Import ClayItemInstance and ClayConfigInstance types
- Update initialize function signatures with explicit types
- Use type narrowing for event handlers and property access
- Replace normalizeColor default case to return empty string
- Flatten layout arrays now have (string | boolean)[][] types
Add types.ts with ClayItemInstance, ClayConfigInstance, and related
interfaces. Move minified.js type declarations to types/ for global
visibility. Add browserify ambient require declaration.
Replace all uses of any with proper interfaces (ClayItemInstance,
ClayConfigInstance, etc.) and all as assertions with type guards
and narrowing. Convert ClayItem to factory function pattern.
Use ClayItemInstance and ClayConfigInstance for initialize methods.
Replace all any/as usage with proper type narrowing and guards.
Use const instead of var throughout.
Mearman added 19 commits April 19, 2026 11:05
- Add imports for ClayConfigItem and ClayMeta from types
- Define ClayOptions, ClayInstance, and PebbleObject interfaces
- Add type annotations to Clay constructor and all prototype methods
- Use type guards for Pebble global (may be undefined)
- Add proper type narrowing for event handlers
- Convert var to const and use proper type signatures
- Replace register appKey check with messageKey check
- Fix typo in comment: "teh use" → "the use"
- Convert config-page.js to TypeScript with proper type annotations
- Add window API type declarations for clayConfig, claySettings, etc.
- Create separate tsconfig for config-page build with lenient type checking
- Update gulpfile to build config-page.ts with tsify plugin
- Use Object.assign instead of _.extend to avoid type compatibility issues
- Cast dynamic values to 'any' where necessary for window API access
- Add type stub for deepcopy module dependency
Replace all as assertions with in-operator narrowing (TS 4.9+).
Change ambient require to return unknown instead of any.
Add createClayConfig factory to avoid new-expression assertions.
Convert fixture, test-utils, and all spec files. Use proper interfaces
for sinon stubs and mock objects. Replace new constructor calls with
factory function pattern.
Update ActiveWatchInfo with optional fields. Add joi type stub.
Fix ambient require to return string for browserify assets.
Add mocha/chai/sinon to tsconfig types. Add createClay factory.
These were created for the curated index.d.ts workflow and are
superseded by the main tsconfig.json now that the source is TypeScript.
Declarations will be auto-generated from the TypeScript source via
tsc --emitDeclarationOnly using tsconfig.build.json.
Point types field at dist-types/index.d.ts. Update build:types and
check:types scripts. Update .npmignore for new file structure.
Fix tsconfig.build.json includes for declaration generation.
Update karma.conf.js file patterns for .ts files.
Fix tsify casing issue in gulpfile.
Remove redundant src/scripts/vendor/templates.d.ts (covered by
types/browserify.d.ts). Remove redundant types/config-page-html.d.ts
(merged into types/browserify.d.ts). Restore types/minified.d.ts
for global interface declarations.
Remove Function types, replace with typed signatures. Fix remaining
var declarations. Remove duplicate M and ActiveWatchInfo interfaces.
Widen ClayConfigItem.defaultValue to include arrays. Remove redundant
in-check in registerComponent. Remove deprecated suppressImplicitAnyIndexErrors.
Replace as any in tests with @ts-expect-error.
Critical: the appKey deprecation check was incorrectly changed to
messageKey during conversion, silently removing the guard. Restored.
Replace as any in tests with @ts-expect-error. Remove deprecated
suppressImplicitAnyIndexErrors option. Add sync comments to minified
type declarations.
Remove tsconfig.config-page.json (tsify uses inline options) and
tsconfig.test.json (unreferenced, tests compile with main tsconfig).
Restore shallow copies of window.clayConfig and window.claySettings
to prevent mutation propagation (behavioural deviation from original).
Add main field pointing to src/js/index.js for npm resolution.
Remove stale .js reference from karma istanbul ignore list.
Use declare global in src/scripts/vendor/minified.d.ts to provide
both global interfaces and module export from a single file. Remove
the duplicate types/minified.d.ts. Update tsconfig to exclude only
vendor .js files, not the whole directory.
…ckage

Update tsconfig.build.json to exclude only vendor .js (matching main
tsconfig). Remove index.ts from .npmignore whitelist — consumers use
the built src/js/index.js, not the TypeScript source.
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.

1 participant