Make Option.env() behave as a getter when called with no arguments#1971
Make Option.env() behave as a getter when called with no arguments#1971aweebit wants to merge 1 commit intotj:developfrom
Option.env() behave as a getter when called with no arguments#1971Conversation
Option.env() behave as a getter when no name is suppliedOption.env() behave as a getter when called with no arguments
|
Unless the property name starts with an underscore, it is public. e.g. Option was once a simple prototype class with all public properties. As new features were added and Option became more full-featured, the existing properties were preserved and the all-public pattern was continued. (Which does lead to some naming gymnastics to have both a property and a chaining setter.) |
It is not included in the typings, though, that's why I though it was private. Had to include it in the manually augmented module declaration along with So do you think it should be added to the library's type declarations instead? Or can we also keep the change I suggest here? It's not always easy to remember which methods are setter-only and which can also be used as getters. Since there is no other meaningful interpretation for an |
Oops, that explains it, I had wondered why you hadn't just used the property!
Yes.
No. |
Another tiny enhancement third-party libraries could benefit from (like #1970).
Problem
I had to use the internal
Option.envVarto build informative error messages in the async-commander library I am currently working on.Solution
Make
Option.env()return the value of the variable when it is called with no parameters.ChangeLog
Added
Option.env()now returns the previously provided environment variable name when called with no argument