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

A version of types.maybe which uses undefined instead of null #830

Closed
pelotom opened this issue May 26, 2018 · 6 comments
Closed

A version of types.maybe which uses undefined instead of null #830

pelotom opened this issue May 26, 2018 · 6 comments
Labels
breaking change Breaking change
Milestone

Comments

@pelotom
Copy link

pelotom commented May 26, 2018

In TypeScript especially, undefined is almost always preferable to null as a representation of unset values, so it would be nice if there was a version of types.maybe (types.maybeUndefined?) which used undefined instead of null.

@Bnaya
Copy link
Member

Bnaya commented May 26, 2018

you have types.optional, which is i think what you look for

@pelotom
Copy link
Author

pelotom commented May 26, 2018

Yes, you can implement it with optional,

function maybeUndefined<S, T>(type: IType<S, T>): IType<S | undefined, T | undefined> {
  return types.optional(types.union(type, types.undefined), undefined);
}

but it would be cool if it were built in 🙂

@mweststrate
Copy link
Member

I think it would be interesting to consider dropping null as default nullable, and use undefined instead. So that for example maybe accepts undefined instead of null, by default etc

@mweststrate mweststrate added this to the 3.0 milestone Jun 18, 2018
@mweststrate mweststrate added the breaking change Breaking change label Jun 18, 2018
@k-g-a
Copy link
Member

k-g-a commented Jun 25, 2018

It seems to me that we could introduce ‘types.nullable’ as direct replacement of current ‘maybe’, and convert ‘maybe’’s default to ‘undefined’, as proposed in previous comment

@k-g-a k-g-a closed this as completed Jun 25, 2018
@k-g-a k-g-a reopened this Jun 25, 2018
@mweststrate
Copy link
Member

Done! In MST 3 types.maybe will use undefined as default value, and types.maybeNull can be used for the old behavior

@sis-dk
Copy link

sis-dk commented Feb 28, 2019

This doc need an update stating this change?
https://mobx-state-tree.gitbook.io/docs/v/new-docs/types-overview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Breaking change
Projects
None yet
Development

No branches or pull requests

5 participants