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

Proposal: Strict Get #313

Closed
asbjornh opened this issue Nov 8, 2021 · 5 comments · Fixed by #317
Closed

Proposal: Strict Get #313

asbjornh opened this issue Nov 8, 2021 · 5 comments · Fixed by #317
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@asbjornh
Copy link
Contributor

asbjornh commented Nov 8, 2021

The Get type is incredibly helpful, so thank you for that!

There is, however, one thing that I wish for. I'm a big fan of defensive typing, and in that regard the Get type has the same shortcoming as native Object[Key] type expressions do: the resulting type doesn't encode failure when dealing with arrays/dictionaries, even when noUncheckedIndexedAccess is enabled. F ex. Get<string[], "[1000000000000000000000000]"> has the type string instead of the more defensive string | undefined.

In general this is easy to get around in userland, but looking at the implementation for Get it doesn't seem like a local proxy type is a feasible way of solving this.

Would you be open to changing the Get type or to adding something like a GetStrict? If so then I'd be happy to do the actual work

@sindresorhus
Copy link
Owner

Yes, I'm open to making the existing Get type stricter.

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Nov 8, 2021
@asbjornh
Copy link
Contributor Author

asbjornh commented Nov 8, 2021

Cool! I guess changing the existing type could be handled in one of three ways:

  • Enforce strictness for all consumers
  • Opt in (type argument)
  • Opt out (type argument)

Do you have a preference?

@sindresorhus
Copy link
Owner

sindresorhus commented Nov 10, 2021

Opt-in through a type argument for now and we can make it opt-out in the next major release.

@danielo515
Copy link

What is wrong about GetStrict?

@asbjornh
Copy link
Contributor Author

asbjornh commented Jan 5, 2022

@danielo515 Nothing in principle I guess, but I suspect it could easily lead to a lot of stuff having to be duplicated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants