ember-cli-typescript
ember-cli-typescript copied to clipboard
Should the `off` method be typed since `on` is typed for the routing service?
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
- [ ] @types/ember__test-helpers
- [ ] @types/ember__service
- [ ] @types/ember-data
- [ ] @types/rsvp
- [x] Other (@types/ember__routing)
- [ ] 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
import Component from "@ember/component";
import RouterService from "@ember/routing/router-service";
import Transition from "@ember/routing/-private/transition";
import { inject as service } from "@ember/service";
function routeWillChange(transition: Transition) {
console.log(transition.to.name);
}
export default class XFoo extends Component {
@service router!: RouterService;
init() {
super.init();
this.router.on("routeWillChange", routeWillChange);
}
willDestroy() {
super.willDestroy();
// can't do this without overriding types :(
this.router.off("routeWillChange", routeWillChange);
}
}
Reproduction Case
If you can, please try to fork this codesandbox, and give us an example that demonstrates the problem. Paste the link below so that we can see what's going on
**Link: ** Could not get codesandox working with a reasonable amount of effort
Now about that bug. What did you expect to see?
I expected to be able to unsubscribe from the event.
What happened instead?
Typescript does not know about the off method.
Thank you for filing this! Per the docs, it doesn't look like either is actually in the public API docs. I'll dig in further, but I believe that this is just a gap in the docs, given that the docs also show using this API!
Cool. That was my interpretation as well!
Resolved by shipping types natively from Ember in ember-source v5.1.