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

No need to convert defaultValue for options of type map #1250

Merged
merged 4 commits into from Mar 29, 2020
Merged

No need to convert defaultValue for options of type map #1250

merged 4 commits into from Mar 29, 2020

Conversation

krisztianb
Copy link
Contributor

Fixes: #1249

The convert function was used to "validate" the default value for all options. This is not necessary for options of type map, since the type of the default value is provided via the template class MapDeclarationOption and must be of the right type. Moreover the conversion throws an error if the default value for the option is of the right type, but not listed in the map of possible values.

private setOptionValueToDefault(declaration: Readonly<DeclarationOption>): void {
if (declaration.scope !== ParameterScope.TypeScript) {
// No nead to convert the defaultValue for a map type as it has to be of a specific type
if (declaration.type === ParameterType.Map) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for your specific usage that illustrates why this is important? The one you posted in gitter should be fine, or even something simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Test added. I ran it through. Previously all but the new test passed. Now all tests pass.

* Sets the value of a given option to its default value.
* @param declaration The option whoes value should be reset.
*/
private setOptionValueToDefault(declaration: Readonly<DeclarationOption>): void {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice to remove duplicate logic.

@krisztianb krisztianb requested a review from Gerrit0 March 29, 2020 19:18
@Gerrit0 Gerrit0 merged commit c296503 into TypeStrong:master Mar 29, 2020
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Mar 29, 2020

Thanks! I'm not sure if I'll get a release out today, next Saturday at the latest. Going to be busy...

@krisztianb
Copy link
Contributor Author

No hurry on this one. 😄

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

Successfully merging this pull request may close these issues.

Declaration option of type ParameterType.Map can't use a defaultValue that is not part of the value map
2 participants