-
Notifications
You must be signed in to change notification settings - Fork 642
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
Comments
I strongly recommend against redefining the type of an existing property,
it is gonna be very confusing for future you :)
…On Sat, Feb 22, 2020 at 3:10 PM hiep294 ***@***.***> wrote:
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
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1473?email_source=notifications&email_token=AAN4NBED2ML4AGAZ6RISTVDREE57ZA5CNFSM4KZSGKU2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IPPRT7Q>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBGXXB7KM2TDOFAM6E3REE57ZANCNFSM4KZSGKUQ>
.
|
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:
That's why I would like to redefine the type |
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 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 , 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. |
I design a models which can be extend like this:
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
The text was updated successfully, but these errors were encountered: