ember-cli-typescript
ember-cli-typescript copied to clipboard
Controller param types in route hooks don't pass type checks
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)
I got bitten by this today too. Is there a know workaround at the moment?
I'm not sure which yet, but we might have been using some outdated dependencies, as it now seems to be working as expected.
ah… I'll have to try and update some deps too then to find what happened…
I'm experiencing this issue also, @bartocc did you manage to track down which dependency was causing it?
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:
-
Switch to using Ember's own preview and stable types, as documented here.
-
Make sure you only have a single copy of the latest version of the various
@typespackages in your project if still using the DT types—remove any duplicate entries from your lock file and re-runnpm 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.
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