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
refactor: move @babel/helper-validator-option to ts #12410
refactor: move @babel/helper-validator-option to ts #12410
Conversation
JLHwung
commented
Nov 27, 2020
•
edited by gitpod-io
bot
edited by gitpod-io
bot
Q | A |
---|---|
License | MIT |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 81b34ac:
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/35001/ |
a32b895
to
12473ca
Compare
@@ -46,13 +45,13 @@ export class OptionValidator { | |||
return value; | |||
} | |||
|
|||
validateStringOption( | |||
validateStringOption<T>( | |||
name: string, | |||
value?: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, value
could be anything here I think (otherwise we wouldn't need this helper).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally value
should be of type that extends string
. So if we accidentally pass number
value to validateStringOption
, the type checker should throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't it be anything, since it's whatever the user gave us as input? We cannot statically know the type of plugin options, so an user could pass a number to a plugin, the plugin will pass a number to this helper, and then this helper will throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also offer our type interface to programmatic users:
{ a: any, b: any }
is technically correct (which is the type user inputs) but not much of value for programmatic usage (API caller) and/or schema check. The validator
here is a runtime enforcement of type checking -- so the user input does match our assumption of types, so it makes sense that if the type checking is good, it is also sound in runtime.
12473ca
to
81b34ac
Compare