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

Controller param types in route hooks don't pass type checks

Open theroncross opened this issue 3 years ago • 3 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
  • [x] @types/ember__routing
  • [ ] @types/ember__application
  • [ ] @types/ember__test
  • [ ] @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

>> Your Instructions Go Here <<
ember g controller application
// controllers/application.js
...
someProp = true;
...
// routes/application.js
import ApplicationController from '../controllers/application';
...
setupController(controller: ApplicationController) {
  controller.someProp = false;
}
...
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: **

Now about that bug. What did you expect to see?

setupController should pass type check

What happened instead?

Property 'setupController' in type 'ApplicationRoute' is not assignable to the same property in base type 'Route<unknown, object>'.
  Type '(controller: ApplicationController) => void' is not assignable to type '(controller: Controller, model: unknown, transition: Transition<unknown>) => void'.
    Types of parameters 'controller' and 'controller' are incompatible.
      Type 'Controller' is missing the following properties from type 'ApplicationController': someProp(2416)

theroncross avatar Mar 10 '22 22:03 theroncross

I got bitten by this today too. Is there a know workaround at the moment?

bartocc avatar Apr 25 '22 09:04 bartocc

I'm not sure which yet, but we might have been using some outdated dependencies, as it now seems to be working as expected.

theroncross avatar Apr 25 '22 13:04 theroncross

ah… I'll have to try and update some deps too then to find what happened…

bartocc avatar Apr 25 '22 14:04 bartocc

I'm experiencing this issue also, @bartocc did you manage to track down which dependency was causing it?

joshuaswift avatar Jan 23 '23 16:01 joshuaswift

FWIW, I've confirmed this issue does not exist with Ember's own types or the latest version of the types on DefinitelyTyped, so I'm going to mark this issue as closed, with the following recommendations as paths forward:

  1. Switch to using Ember's own preview and stable types, as documented here.

  2. Make sure you only have a single copy of the latest version of the various @types packages in your project if still using the DT types—remove any duplicate entries from your lock file and re-run npm install, yarn, etc.

If those don't help, feel free to continue commenting here, but note that I am going to mark the issue as closed since I can confirm it's not an issue with the types themselves.

chriskrycho avatar Jan 24 '23 03:01 chriskrycho

We are in the process of upgrading to

Ember's own types

I'll make sure we don't have this issue anymore after that

bartocc avatar Jan 24 '23 09:01 bartocc