Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescripts/Javascript set hint not correctly in overriding props #1473

Closed
hiep294 opened this issue Feb 22, 2020 · 5 comments
Closed

Typescripts/Javascript set hint not correctly in overriding props #1473

hiep294 opened this issue Feb 22, 2020 · 5 comments
Labels
should be ready to close Should be ready to close soon if nothing else comes up

Comments

@hiep294
Copy link

hiep294 commented Feb 22, 2020

I design a models which can be extend like this:

const ProductList = types.model({
  items: types.map(types.model({
    price: types.optional(types.string, '')
  }))
})

const ProductListExtend = types.compose(
  ProductList,
  types.model({
    items: types.map(types.model({
      price: types.optional(types.number, 1)
    }))
  })
)

const List = ProductListExtend.create()
List.items.forEach(item => {
  // item is showing that it contain a string price, but a number is expected
})

In design above, items of ProductListExtend will be a map list of item which has price is a number. however, item is showing a hint that containing a price is a string.
My question is: Is there any way to show a hint correctly in javacriipt or typescript

@mweststrate
Copy link
Member

mweststrate commented Feb 22, 2020 via email

@hiep294
Copy link
Author

hiep294 commented Feb 22, 2020

I have many lists like types.model({items: types.map(A)}) with the same actions. I put these actions into GeneralList, also need to define 'items' prop in GeneralList, because these actions will apply the a specific result to items. in overview:

const GeneralList = types.model({
  items: types.map(GeneralModel)
}).actions(...common actions required 'items' prop)

const ListOfA = types.compose(
  GeneralList, 
  types.model({
    items: types.map(A)
}))

That's why I would like to redefine the type

@coolsoftwaretyler
Copy link
Collaborator

Hey @hiep294 - I know it's been a while since anyone got back to you here, but I think @mweststrate has a good point that re-defining the properties is an anti-pattern here.

What you might consider doing instead is defining some utility functions that don't know anything about MST at all, and using them in the actions block for better code reuse.

Is this still a relevant problem for you? Do any of these suggestions help out? Let me know and we can try to resolve it. Otherwise, I'll close this issue out if I don't hear back in two weeks or so.

@coolsoftwaretyler coolsoftwaretyler added the should be ready to close Should be ready to close soon if nothing else comes up label Jun 30, 2023
@k-g-a
Copy link
Member

k-g-a commented Jul 3, 2023

@coolsoftwaretyler , just wanted to mention that this is the same as 1403.

@hiep294 , if this is still relevant, check out the proposed workaround from the above issue.

@coolsoftwaretyler
Copy link
Collaborator

Thanks @k-g-a! Good call. I'm going to close this issue out in favor of the workarounds in #1403 + perhaps some day we'll add some kind of official support to if (PRs welcome from the interested).

Thanks y'all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
should be ready to close Should be ready to close soon if nothing else comes up
Projects
None yet
Development

No branches or pull requests

4 participants