ember-cli-typescript
ember-cli-typescript copied to clipboard
ember__routing/route.d.ts does not necessarily have to take a `string` as the first argument
Which package(s) does this problem pertain to?
- [X] @types/ember__routing
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
cat << EOF > app/routes/application.ts
import Route from '@ember/routing/route';
interface QueryParams {
page: number
}
export default class Application extends Route {
model(params: QueryParams) {
const query = {
page: {
number: params.page,
size: 20,
},
}
return this.store.query('my-model', query).then(myModel => {
if (myModel.length === 0 && query.page.number !== 1) {
return this.replaceWith({ queryParams: { page: 1 } })
}
return myModel
})
}
queryParams = {
page: {
refreshModel: true,
},
}
}
EOF
ember build
Now about that bug. What did you expect to see?
Expected a clean build
What happened instead?
app/routes/application.ts:18:33 - error TS2345: Argument of type '{ queryParams: { page: number; }; }' is not assignable to parameter of type 'string'.
18 return this.replaceWith({ queryParams: { page: 1 } })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this.replaceWith() should be able to take an object (without a string) as a first argument.
Confirmed—the API should match transitionTo, where I believe we do supply that override! Thanks for the bug report!
Resolved by shipping types from Ember itself, where it cannot get out of line with the source of truth. 🎉
(Also Routes no longer have that API!)