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

Proper TS types #117

Merged
merged 4 commits into from
Sep 29, 2020
Merged

Proper TS types #117

merged 4 commits into from
Sep 29, 2020

Conversation

Andarist
Copy link
Contributor

Specifying unfetch type as the same as fetch is a stretch - so I've written down better, more accurate types.

@Andarist
Copy link
Contributor Author

Andarist commented Dec 3, 2019

@developit friendly 🏓

Copy link
Owner

@developit developit left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I wonder if it'll cause folks trouble because the types are now different for unfetch VS isomorphic-unfetch? You'd know better than I, I'm not much of a TS user.

@Andarist
Copy link
Contributor Author

This looks good to me, but I wonder if it'll cause folks trouble because the types are now different for unfetch VS isomorphic-unfetch?

Well, depends on how you look at it. It won't cause people much trouble because one is probably not using both in the same project, but I don't know how to properly support types from this PR when using isomorphic-unfetch. I'm not aware of any way to make TS resolve types based on target environment or anything like that - it always resolves node_modules to "main".

So landing this would definitely make both of those packages providing different typings, but at least for browser-only unfetch users they would be correct and would save users from using it like a regular, full-blown fetch.

@developit
Copy link
Owner

Makes sense. Anyone using isomorphic-unfetch is unaffected by this change then, they'll still get the (incorrect, but uniform) types from node-fetch?

@Andarist
Copy link
Contributor Author

Yes - thats my understanding. Isomorphic-fetch wont even know about those typings here because they are not referenced anyhow from there

@@ -12,6 +12,33 @@ declare namespace unfetch {
export type IsomorphicRequest = Request | NodeRequest
}

declare const unfetch: typeof fetch;
type UnfetchResponse = {
Copy link

Choose a reason for hiding this comment

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

Wouldn't it be better if we export this type so that TS developers could use it in their code?

}
}

type Unfetch = (
Copy link

Choose a reason for hiding this comment

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

Same

@Andarist
Copy link
Contributor Author

Andarist commented Aug 6, 2020

@developit friendly 🏓

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.

3 participants