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

initial value of createStorage mandatory? #1

Open
simonihmig opened this issue Jan 7, 2022 · 2 comments
Open

initial value of createStorage mandatory? #1

simonihmig opened this issue Jan 7, 2022 · 2 comments

Comments

@simonihmig
Copy link

According to the RFC, the initial value of createStorage() should be optional:

declare function createStorage<T>(
  initialValue?: T,
  isEqual?: (oldValue: T, newValue: T) => boolean
): Storage<T>;

But here it is mandatory! Intentionally, or by accident?

@wycats
Copy link

wycats commented Apr 22, 2022

I think it makes sense for it to be mandatory. If you want to create storage that is allowed to be undefined, then your T includes undefined 😄

@simonihmig
Copy link
Author

Sure, I just wanted to clarify this as the RFC is supposed to be normative, and it explicitly specifies the signature slightly different than implemented.

AFAICT under the RFC this would have been valid, while it is not in this implementation:

const storage = createStorage<string>(undefined, (a, b) => a.toLowerCase() === b.toLowerCase());

And with T=string|undefined a and b could be undefined, so still invalid...

This is just a contrived example. I am fine either way. But if we stick with what we have now, I think the final implementation of the RFC should then also follow this, and not the RFC, to not create subtle breaking changes (at least for the types), right?

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

No branches or pull requests

2 participants