Skip to content

Convert src to TypeScript and test the published types - #798

Merged
NullVoxPopuli merged 2 commits into
masterfrom
typescript
Oct 9, 2026
Merged

NullVoxPopuli merged 2 commits into
masterfrom
typescript

Conversation

@NullVoxPopuli

Copy link
Copy Markdown
Contributor

ember-keyboard now publishes real types. src/ is TypeScript, and a new test-types package checks the published declarations with expect-type in CI.

Closes #464. This supersedes #769, which added a hand-written addon/index.d.ts for the pre-v2 layout.

What consumers get

  • Typed exports from ember-keyboard: keyResponder, onKey, the listener-name helpers (keyDown, mouseDown, ...), and triggerKey*.
  • Exported types: KeyboardResponder, KeyboardHandler, EmberKeyboardEvent, EmberKeyboardConfig, and the Glint signatures OnKeyModifierSignature, OnKeyHelperSignature, IfKeySignature.
  • Glint signatures on helpers/on-key, helpers/if-key and modifiers/on-key, so bad args fail in .gts templates.
  • KeyboardService is in the @ember/service registry, so owner.lookup('service:keyboard') is typed.
  • package.json#exports now has types for . and both test-support/* entries. Before, import { onKey } from 'ember-keyboard' resolved to no types at all. I also added typesVersions for consumers still on node10 resolution.

Runtime changes

The goal was no behavior change. The tests (206 pass, 2 skipped, same as master) agree. Small things you might notice in the diff:

  • modifiers/on-key: both class variants are now at module level, and macroCondition picks one in a ternary. TypeScript doesn't allow decorators on class expressions.
  • keyResponder sets the class name with Object.defineProperty, because TS rejects static name.
  • handle-key-event: removed the if (ekEvent) branch. Both callers always pass ekEvent, so the branch was never used.
  • src imports use .ts extensions, and so do the #src/* imports in tests/ and demo-app/.

Type tests

test-types/ is a private workspace package. It depends on ember-keyboard: workspace:* and type-checks against the built declarations/, not src/. That way it catches broken exports and bad declaration output. It covers the index exports, decorators, the service and registry, test-support, and template invocations of the helpers and modifier (including @glint-expect-error cases). I checked that the suite fails when an assertion is wrong.

CI has a new "Type Tests" job that runs pnpm build && pnpm --filter test-types test.

Not included

  • No loose-mode Glint template registry. The on-key helper and the on-key modifier share a name, and a single registry key can't hold both. Strict-mode imports work.
  • Glint doesn't report a missing trailing positional arg on a class-based helper ({{onKey "a"}}), so there is no test for that case.

🤖 Generated with Claude Code

NullVoxPopuli and others added 2 commits October 6, 2026 17:04
Only `git mv`, no content changes, so the conversion in the next
commit shows up as a diff against the original files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Generated declarations were mostly `any` because src was JS. This
converts src to TS, adds Glint signatures for the helpers and modifier,
registers the keyboard service, and adds `types` conditions to the
package exports that were missing them.

A new `test-types` workspace package checks the published declarations
with expect-type, and a "Type Tests" CI job runs it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Comment thread package.json
},
"./test-support/key-event": "./dist/test-support/key-event.js",
"./test-support/test-helpers": "./dist/test-support/test-helpers.js",
"./test-support/key-event": {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in another PR, since we're preparing for a major -- we should just have test-support

@MelSumner

Copy link
Copy Markdown
Contributor

Glint doesn't report a missing trailing positional arg on a class-based helper ({{onKey "a"}}), so there is no test for that case.

@NullVoxPopuli any insight into why not?

@NullVoxPopuli

Copy link
Copy Markdown
Contributor Author

any insight into why not?

not at the moment -- will look in to it

@NullVoxPopuli
NullVoxPopuli merged commit 663cef5 into master Oct 9, 2026
10 checks passed
@NullVoxPopuli
NullVoxPopuli deleted the typescript branch October 9, 2026 19:03
@github-actions github-actions Bot mentioned this pull request Oct 6, 2026
@NullVoxPopuli

Copy link
Copy Markdown
Contributor Author

turns out to be fixed -- glint just needs updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide TypeScript types

2 participants