ember-cli-typescript
ember-cli-typescript copied to clipboard
`triggerKeyEvent` results in a type error when passed `document` as the first argument
Which package(s) does this problem pertain to?
- [ ] @types/ember
- [ ] @types/ember__string
- [ ] @types/ember__polyfills
- [ ] @types/ember__object
- [ ] @types/ember__utils
- [ ] @types/ember__array
- [ ] @types/ember__engine
- [ ] @types/ember__debug
- [ ] @types/ember__runloop
- [ ] @types/ember__error
- [ ] @types/ember__controller
- [ ] @types/ember__component
- [ ] @types/ember__routing
- [ ] @types/ember__application
- [ ] @types/ember__test
- [X] @types/ember__test-helpers
- [ ] @types/ember__service
- [ ] @types/ember-data
- [ ] @types/rsvp
- [ ] Other
- [ ] I don't know
What are instructions we can follow to reproduce the issue?
ember new sample; cd ./sample # Create a new ember app
ember install ember-cli-typescript # Set up typescript support
In a TS test file, try to use the `triggerKeyEvent` DOM interaction helper with `document` as the first argument, e.g.
await triggerKeyEvent(document, 'keydown', 'Escape');
Now about that bug. What did you expect to see?
I expected document to be a valid target to pass to triggerKeyEvent and for it to not cause a type error. See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
What happened instead?
TypeScript seems to think triggerKeyEvent cannot accept an argument of type Document even thought the function does accept it.
This causes the following type error: "Argument of type 'Document' is not assignable to parameter of type 'Target'. Type 'Document' is missing the following properties from type 'Element': attributes, classList, className, clientHeight, and 58 more. glint:ts(2345)"
I opened a PR on DefinitelyTyped with a potential fix: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55123
Thanks for opening this! For anyone else watching this issue: the types on DT match the docs, but the actual implementation totally supports (and has types to support!) using document, so once we land updates to the docs we'll land the DT PR @eramod opened. 🎉
I believe this should be fixed now because @ember/test-helpers ships its own types natively, so this cannot get out of sync. 🎉