Sitelet https://web.archive.org/web/20201201154505/https://github.com/developit/unfetch/pull/117
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

@Andarist Andarist commented Jun 28, 2019

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 Andarist commented Dec 3, 2019

@developit friendly 🏓

Copy link
Owner

@developit developit left a comment

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

@Andarist Andarist commented Feb 18, 2020

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

@developit developit commented Feb 19, 2020

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

@Andarist Andarist commented Feb 19, 2020

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 = {

This comment has been minimized.

@1999

1999 Feb 25, 2020

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

}
}

type Unfetch = (

This comment has been minimized.

@Andarist
Copy link
Contributor Author

@Andarist Andarist commented Aug 6, 2020

@developit friendly 🏓

@developit developit merged commit aff2b9d into developit:master Sep 29, 2020
1 of 2 checks passed
1 of 2 checks passed
build
Details
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
@Andarist Andarist deleted the Andarist:better-types branch Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.