ember-cli-typescript icon indicating copy to clipboard operation
ember-cli-typescript copied to clipboard

Should the `off` method be typed since `on` is typed for the routing service?

Open jeffhertzler opened this issue 5 years ago • 2 comments

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.

jeffhertzler avatar Jun 09 '20 21:06 jeffhertzler

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!

chriskrycho avatar Jun 13 '20 00:06 chriskrycho

Cool. That was my interpretation as well!

jeffhertzler avatar Jun 15 '20 23:06 jeffhertzler

Resolved by shipping types natively from Ember in ember-source v5.1.

chriskrycho avatar Sep 28 '23 23:09 chriskrycho