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

ember__routing/route.d.ts does not necessarily have to take a `string` as the first argument

Open psbanka opened this issue 6 years ago • 1 comments

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.

psbanka avatar Jul 30 '19 23:07 psbanka

Confirmed—the API should match transitionTo, where I believe we do supply that override! Thanks for the bug report!

chriskrycho avatar Jul 31 '19 14:07 chriskrycho

Resolved by shipping types from Ember itself, where it cannot get out of line with the source of truth. 🎉

chriskrycho avatar Sep 28 '23 22:09 chriskrycho

(Also Routes no longer have that API!)

chriskrycho avatar Sep 28 '23 22:09 chriskrycho