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

Same problem with [email protected] ([email protected], [email protected], [email protected]):

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 commented Oct 17, 2018

@egasimus I don't think that is the same issue. Typescript definitions were added in [email protected], 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 commented Oct 17, 2018

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

@stephenmathieson
Copy link
Contributor

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

@O4epegb
Copy link

O4epegb commented Oct 24, 2018

Not true, just .d.ts is incorrect.

@balupton
Copy link

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 commented Oct 21, 2019

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

@igl
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants