mardi 17 septembre 2019

How to fix type checking when using this.store.findRecod

In my ember.js project, I type check javascript files with Typescript and the checkJs option.

Here is a simple route.js file example

import Route from '@ember/routing/route';

export default class UsersRoute extends Route {
  model() {
    return this.store.findAll('user');
  }

}

With this code, I get the following Typescript error

route.js:5:31 - error TS2345: Argument of type '"user"' is not assignable to parameter of type 'never'.

5     return this.store.findAll('user');
                                ~~~~~~

The ember-data type definitions are provided by the @types/ember-data package, and here is the findAll definition

findAll<K extends keyof ModelRegistry>(
    modelName: K,
    options?: {
        reload?: boolean;
        backgroundReload?: boolean;
        include?: string;
        adapterOptions?: any;
    }
): PromiseArray<ModelRegistry[K]>;

This is how far I could go while investigating how findAll was defined.

In theory, this.store.findAll('user'); is valid, but what should I do to fix this Typescript error?




Aucun commentaire:

Enregistrer un commentaire