xaviergonz / mobx-keystone

A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
https://mobx-keystone.js.org
MIT License
554 stars 25 forks source link

Extending model that customizes idProp #243

Closed dodas closed 3 years ago

dodas commented 3 years ago

Hi! Many thanks for this wonderful library again 🙏

I have a base model that customizes the id prop to id:

@model("BaseModel")
class BaseModel extends Model({
  id: idProp,
}) {}

Then I extend this model with some other props:

@model("MyModel")
class MyModel extends ExtendedModel(BaseModel, {
  name: prop<string>(),
}) {}

But I get this TS error:

Base constructor return type 'never' is not an object type or intersection of object types with statically known members.
  The intersection 'BaseModel & import("/my-project/node_modules/mobx-keystone/dist/model/BaseModel").BaseModel<...> & Omit<...> & ModelPropsToSetter<...>' was reduced to 'never' because property '[modelIdPropertyNameSymbol]' has conflicting types in some constituents.ts(2509)

I tried customizing the idProp on the extended model as well, but that causes an runtime error:

Error: extended model cannot redeclare base model property named 'id'

Looks like the same thing happens when I instead remove idProp from the base model and add it in each extended model.

Any hints, please? Thanks!

xaviergonz commented 3 years ago

Thanks for reporting. The fix is out in v0.58.1 Please close it if it is fixed in your side 👍

dodas commented 3 years ago

Yes, this fixes my issue. Many thanks!