★ wanayoo — archive 1999 https://github.com/developit/unfetch/issues/99Nouvelle recherche | Portail wanayoo
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

Is the typescript definition exported correctly? #99

Closed
Fnatte opened this issue Oct 15, 2018 · 8 comments
Closed

Is the typescript definition exported correctly? #99

Fnatte opened this issue Oct 15, 2018 · 8 comments

Comments

@Fnatte
Copy link

@Fnatte Fnatte commented Oct 15, 2018

I'm having trouble with unfetch >= 3.1.1. The new TypeScript definition actually broke our build, and I'm not sure how to fix it.

The change was made in PR #89, in which the default export was removed from src/index.d.ts. Was this intentional? The PR is named "Fix isomorphic-unfetch definition" but packages/isomorphic-unfetch/index.d.ts is not changed, instead src/index.d.ts was changed.

Since src/index.mjs export default, shouldn't src/index.d.ts also export default?

@egasimus
Copy link

@egasimus egasimus commented Oct 16, 2018

Same problem with unfetch@3.0.0 (webpack@3.12.0, ts-loader@2.3.7, typescript@2.9.2):

error TS7016: Could not find a declaration file for module 'unfetch'. '/home/user/Edge/Demo/node_modules/unfetch/dist/unfetch.js' implicitly has an 'any' type.
@Fnatte
Copy link
Author

@Fnatte Fnatte commented Oct 17, 2018

@egasimus I don't think that is the same issue. Typescript definitions were added in unfetch@3.1.0, so that is probably why the declaration file can't be found in your case.

Some more info on my issue:

import * as fetch from 'unfetch';
console.log(fetch); // { default: f(), __esModule: true }
import fetch from 'unfetch';
// error TS1192: Module '"node_modules/unfetch/src/index"' has no default export

The last example works if I enable allowSyntheticDefaultImports, but that was not required before.

@O4epegb
Copy link

@O4epegb O4epegb commented Oct 17, 2018

Yep, just updated to v4 and have same issue. Definitions are definitely incorrect.

@stephenmathieson
Copy link
Contributor

@stephenmathieson stephenmathieson commented Oct 24, 2018

I believe this is due to TypeScript not respecting the .mjs extension.

@O4epegb
Copy link

@O4epegb O4epegb commented Oct 24, 2018

Not true, just .d.ts is incorrect.

@balupton
Copy link

@balupton balupton commented Dec 31, 2018

So if you do import fetch from 'isomorphic-unfetch' then the types work fine, but it fails to run, due to TypeError: isomorphic_unfetch_1.default is not a function

Searching that error, returns the recommendation of doing the following for commonjs modules import fetch = require('isomorphic-unfetch') however, then typescript complains there are no types, as the type definition is done with esmodules in mind, not commonjs modules

As such, I've done the following workaround for it:

import * as fetchImport from 'isomorphic-unfetch'
const fetch = (fetchImport.default || fetchImport) as typeof fetchImport.default
@samayo
Copy link

@samayo samayo commented Oct 21, 2019

Still getting this error. Is there a fix for it?

@igl
Copy link

@igl igl commented Jul 15, 2020

if you do import fetch from 'isomorphic-unfetch' then the types work fine

What am i missing here? there are no types but just a typeof fetch which resolves to any

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.