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

How to use require and first together? #13

Closed
renatoargh opened this issue Feb 26, 2021 · 4 comments
Closed

How to use require and first together? #13

renatoargh opened this issue Feb 26, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@renatoargh
Copy link

I have the case where I have two defaults, if none of them are present I want an exception to happen, for example:

// this is just an example with imaginary code (from the tests I know it does work)
const project = env.require(['FIRST_ENV', 'SECOND_ENV'])

The project variable, in this case, would also benefit because it could be typed as a string and not as a string | undefined as when I use just .require

@renatoargh
Copy link
Author

By the way, great work! Congrats :)

@nzakas
Copy link
Contributor

nzakas commented Feb 26, 2021

That's not currently supported. I think you're looking for something like a requireFirst() method?

@nzakas nzakas added the enhancement New feature or request label Feb 26, 2021
@renatoargh
Copy link
Author

Yeah, that name makes sense! I had the same idea :)

I think it is important to make sure that the type returned is T and not T | undefined so that we don't have to perform any checks afterward (since it is either there or an exception was thrown)

Thanks for the quick reply

@nzakas
Copy link
Contributor

nzakas commented Mar 1, 2021

That's a good point. I'm open to adding a new method, I just need to think through the naming and function signature a bit.

@nzakas nzakas closed this as completed in 13e1b9d Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants