-
Notifications
You must be signed in to change notification settings - Fork 340
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
Make options optional no default function parameter initializer (BETA) #179
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What is wrong with providing a default? I am not sure I follow.
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.
By using the default, the line here seems like dead-code. I want to leave that line because of people passing in null and not using anything that tells them it shouldnt. We could consider ensuring the types support
null
as well, but there shouldn't be no need for people to pass in null, so I'd rather not signal that in the public API.By removing the default, that line is now also covered when passing in undefined (or nothing), making it no longer dead-code when looking at it from a types point of view.
I don't mind adding in that change, as I introduced the overload in the beta to begin with, and I believe it may not have been 100% accurate.
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.
Hmmm, yeah I see. The current types that are already in a published version also marked this as optional, so the types should remain the same.
I guess this is a question of whether the library should do all this validation, or if that is the job of TypeScript. And if users don't use TypeScript, should we handle all these edge cases of input validation in code?
I'd argue that if users need to validate their input is correct, that they should adopt TypeScript. Especially considering we'd essentially be shipping more code, such as the run-time type checks to the user, even if they are running in production. I'd even argue we should remove the existing checks for specific types, and make a clean break to let TypeScript handle such things.
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.
Thie library didnt use TypeScript before v4, and we introduced TypeScript for convenience and easier tool alignment.
We don't want to make any assumptions on our users using typescript, that's not the scope of the new major.
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.
Yup i'm also accustomed to rely on TypeScript or intellisense / code completion from the editors. So as you say @jonkoops most people should get an warning should they ever try to pass null in an editor that uses intellisense and relies on the types.
However as @frederikprijck says here, there may be people out there that are passing null an won't get an warning when upgrading, should we had rely on the types only we should have then perhaps added an assert instead that checks if the passed input is null an throw an error instead.
This is an easy fix and we retain the same logic with the
options = options || {}
initializer as before.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.
Users that use an editor with intellisense / code completion that leverages typescript definitions file would have gotten an error/warning if they passed null as an argument does not matter if they are using TypeScript or not. Since most modern editors have some basic type checking built in by default or in a JS environment where a JavaScript LSP plugin is used.