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

Strict check #157

Merged
merged 3 commits into from
Jan 26, 2024
Merged

Strict check #157

merged 3 commits into from
Jan 26, 2024

Conversation

ayrton
Copy link
Contributor

@ayrton ayrton commented Dec 18, 2023

Stronger type safety through strict checking

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
src/index.ts Outdated
if (typeof fetch !== 'undefined') {
this.config.fetch ||= fetch
if (!config.fetch && typeof fetch === 'undefined') {
throw new Error('No `fetch` implementation available')
Copy link
Member

Choose a reason for hiding this comment

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

To me, this is the only thing that seems like change in behavior.

So i understand, before if there was no fetch passed into the config and no global fetch available, we'd have not failed in the constructor, but failed later inside of postJSON when we tried to execute the undefined thing. Correct?

But our change here catches this in the constructor and yells before trying to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct. These days it's unlikely there's no fetch available but rather than have an internal Node exception bubble up. I wanted to fail fast with a clear exception message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this a little in ecae723.

this.fetch = config.fetch || fetch!

This will raise a Uncaught ReferenceError: fetch is not define - which is easily googlable

@ayrton ayrton merged commit 07a2329 into main Jan 26, 2024
@ayrton ayrton deleted the strict-check branch January 26, 2024 16:47
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.

None yet

3 participants