-
Notifications
You must be signed in to change notification settings - Fork 641
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
Optional default gets a Typescript complaint #1308
Comments
Might be related to this? |
I think its related to #1307 |
@bryanstearns, please check your {
"strict": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitAny": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitThis": true
} |
(please note that sandbox might not pick up compiler flag changes from my experience, so best test it locally or on stackblitz) |
Any update on this ? |
Thanks for the follow up @thegedge! I do not see this error on v6 either, so I'm going to close it out. For everyone else in the thread, sorry this has stayed open for so long, although we have definitely had a fix out for a little while. If y'all need anything else, we can always reopen. Have a great day! |
Bug report
When declaring an optional default for a model with entirely defaultable properties, I get a typescript error that I haven't been able to figure out.
Sandbox link or minimal reproduction code
https://codesandbox.io/s/optionaldefaultproblem-qx08w
Describe the expected behavior
Before I discovered this problem when upgrading a project from much older mobx (4.2.1) & mobx-state-tree (2.0.5) versions, this worked: I could initialize MST models with naked-object snapshots and leave out
maybe
oroptional
properties if I wanted.Describe the observed behavior
If I don't specify values for all the properties when building the snapshot object to use as the default, Typescript complains:
I get essentially the same error if I define ChildModel's
flag
astypes.optional(types.boolean, false)
(or justfalse
, which is the same thing, right?).If I do
child: types.optional(ChildModel, { aProp: false })
instead (with either declaration,optional
ormaybe
), the error goes away.The text was updated successfully, but these errors were encountered: