emberjs / data

WarpDrive is a lightweight data library for web apps — universal, typed, reactive, and ready to scale.
https://api.emberjs.com/ember-data/release
MIT License
3.04k stars 1.33k forks source link

Descendants of 'Model' cannot be upcast #9513

Open MathieuCouette opened 4 months ago

MathieuCouette commented 4 months ago

Reproduction

  1. Clone https://github.com/MathieuCouette/ember-data-issues
  2. Check out model-upcasting-issue
  3. Run npm install && npm run lint

Description

Implicit upcasting of indirect descendants of Model does not work when the child has an attribute or relationship that the parent does not.

image

Source file: https://github.com/MathieuCouette/ember-data-issues/blob/d2b31433b1212b03879288990b763f9299c33e34/app/components/product.ts

Argument of type 'PaymentMethodCcModel' is not assignable to parameter of type 'PaymentMethodModel'.
  Types of property 'eachAttribute' are incompatible.
    Type '<T>(callback: (this: NoInfer<T> | undefined, key: "last4" | "obfuscatedIdentifier", meta: LegacyAttributeField) => void, binding?: T | undefined) => void' is not assignable to type '<T>(callback: (this: NoInfer<T> | undefined, key: never, meta: LegacyAttributeField) => void, binding?: T | undefined) => void'.
      Types of parameters 'callback' and 'callback' are incompatible.
        Types of parameters 'key' and 'key' are incompatible.
          Type 'string' is not assignable to type 'never'.
            Type 'string' is not assignable to type 'never'.

I am guessing that the cause is the same as #9405.

Versions

├── @babel/core@7.24.9
├── @ember-data-types/adapter@5.3.8
├── @ember-data-types/graph@5.3.8
├── @ember-data-types/json-api@5.3.8
├── @ember-data-types/legacy-compat@5.3.8
├── @ember-data-types/model@5.3.8
├── @ember-data-types/request-utils@5.3.8
├── @ember-data-types/request@5.3.8
├── @ember-data-types/serializer@5.3.8
├── @ember-data-types/store@5.3.8
├── @ember-data-types/tracking@5.3.8
├── @ember/optional-features@2.1.0
├── @ember/string@3.1.1
├── @ember/test-helpers@3.3.0
├── @glimmer/component@1.1.2
├── @glimmer/tracking@1.1.2
├── @glint/environment-ember-loose@1.4.0
├── @glint/template@1.4.0
├── @tsconfig/ember@3.0.8
├── @types/qunit@2.19.10
├── @types/rsvp@4.0.9
├── @typescript-eslint/eslint-plugin@6.21.0
├── @typescript-eslint/parser@6.21.0
├── @warp-drive-types/core-types@0.0.0-beta.11
├── broccoli-asset-rev@3.0.0
├── concurrently@8.2.2
├── ember-auto-import@2.7.4
├── ember-cli-app-version@6.0.1
├── ember-cli-babel@8.2.0
├── ember-cli-clean-css@3.0.0
├── ember-cli-dependency-checker@3.3.2
├── ember-cli-htmlbars@6.3.0
├── ember-cli-inject-live-reload@2.1.0
├── ember-cli-sri@2.1.1
├── ember-cli-terser@4.0.2
├── ember-cli@5.10.0
├── ember-data-types@5.3.8
├── ember-data@5.3.8
├── ember-fetch@8.1.2
├── ember-load-initializers@2.1.2
├── ember-modifier@4.2.0
├── ember-page-title@8.2.3
├── ember-qunit@8.1.0
├── ember-resolver@11.0.1
├── ember-source@5.10.1
├── ember-template-lint@5.13.0
├── ember-welcome-page@7.0.2
├── eslint-config-prettier@9.1.0
├── eslint-import-resolver-custom-alias@1.3.2
├── eslint-import-resolver-typescript@3.6.1
├── eslint-plugin-ember@11.12.0
├── eslint-plugin-import@2.29.1
├── eslint-plugin-n@16.6.2
├── eslint-plugin-prettier@5.1.3
├── eslint-plugin-qunit@8.1.1
├── eslint@8.57.0
├── loader.js@4.7.0
├── prettier@3.3.3
├── qunit-dom@2.0.0
├── qunit@2.21.0
├── stylelint-config-standard@34.0.0
├── stylelint-prettier@4.1.0
├── stylelint@15.11.0
├── tracked-built-ins@3.3.0
├── typescript@5.5.3
└── webpack@5.93.0
mkszepp commented 3 months ago

we have in our project the same issue (more than one usecase with different models)... is there any workaround how we can fix it without adding // @ts-expect error ...?