-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Consider limiting input
type to string
#142
Comments
If you agree, I'm happy to submit a PR : ) |
@harveysanders Thanks for the feedback. I initially included null and undefined because of JavaScript being a dynamic language. I really like your explanation that TypeScript should tell the users the correct type and totally agree with your points. Please help raise a PR to fix this. |
@motss thanks for the quick response. Sounds good! I'll try to get one in next week : ) |
@motss I've just submitted a PR |
Description
The type for parameter
input
innormalizeSync
implies thatundefined
andnull
are acceptable inputs. However, the first line of the function throws an error if the input is not astring
.https://github.com/motss/normalize-diacritics/blob/main/src/normalize-sync.ts#L3-L6
I believe it would be more ergonomic to have TypeScript signal to the dev that only
string
s are acceptable.In my opinion, TS is best suited to help devs avoid runtime errors by attempting to move common issues to compile-time errors. With this in mind, I think it would be more helpful to set
input
to onlystring
.That way we get type errors before running the code:
What do you think?
Anyway, thanks for building this lib 🙂
The text was updated successfully, but these errors were encountered: