[Typescript] Overriden model props get 'never'/'multiple implementation' typings

Author: k-g-aCreated Oct 16, 2019Updated Feb 20, 2025
Labelsbrainstorming/wild ideadocs or examples

Bug report

  • I've checked documentation and searched for existing issues
  • I've made sure my project is based on the latest MST version
  • Fork this code sandbox or another minimal reproduction.

Sandbox link or minimal reproduction code

https://codesandbox.io/s/goofy-dewdney-u7sbo

Describe the expected behavior

Overriding prop via ModelType.props(NEW_PROPS) updates it's typings.

Describe the observed behavior

We get union type, which ends up in never for simple types (Problem #1 at sandbox) or multiple implementations for complex ones (Problem #2 at sandbox).

It seems like instead of doing (at model.ts):

typescript
props<PROPS2 extends ModelPropertiesDeclaration>(
        props: PROPS2
    ): IModelType<PROPS & ModelPropertiesDeclarationToProperties<PROPS2>, OTHERS, CustomC, CustomS>

We should do something like:

typescript
props<PROPS2 extends ModelPropertiesDeclaration>(
        props: PROPS2
    ): IModelType<Omit<PROPS, keyof PROPS2> & ModelPropertiesDeclarationToProperties<PROPS2>, OTHERS, CustomC, CustomS>

The Omit<...> part is added. But my quick experiment ended up with dozens of type errors. I can make a PR if any solution is found.