data icon indicating copy to clipboard operation
data copied to clipboard

[5.4.0-alpha.91] Incorrect/Missing typings

Open mkszepp opened this issue 8 months ago • 4 comments

I have recently updated in our app the native type packages from 5.4.0-alpha.49 to 5.4.0-alpha.91

After updating we have seen that there already fixed other incorrect types (thanks for that), but other types are now incorrect or maybe other improvements are bringing now incorrect TS errors

  1. The option include was defined as array. it should be a string, otherwise the JSONAPI call is incorrect. Passing as array generates url &include[]=pets, which is not correct. demo - JSON:API Specs. This error is in findAll, findRecord, query... (i think in all legacy functions)
const users = await this.store.findAll<UserModel>('user', {
    // Error "Type 'string' is not assignable to type 'undefined[]'.ts(2322)"
    include: 'pets',
  });
  1. When we a findAll returns a list of models and we take for example the first to make additional calls like findRecord, we see error Error Argument of type 'string | null' is not assignable to parameter of type 'string | number'. Type 'null' is not assignable to type 'string | number'.ts(2345) demo Expected: id should be string | number, instead of string | null
user = await this.store.findRecord<UserModel>('user', firstUser.id, {
        include: 'pets',
      });
  1. We have used in some models this.constructor.relationshipsByName;. In this case we get error "Property 'relationshipsByName' does not exist on type 'Function'.". This works in JS... but typing looks like incorrect or missing see
 relationshipNames() {
    // Error "Property 'relationshipsByName' does not exist on type 'Function'."
    return this.constructor.relationshipsByName;
  }

All TS errors you can find in this repo: https://github.com/mkszepp/ember-data-ts-errors

mkszepp avatar Jun 25 '24 08:06 mkszepp