question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is the typescript definition exported correctly?

See original GitHub issue

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 https://github.com/developit/unfetch/pull/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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
baluptoncommented, 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
5reactions
samayocommented, Oct 21, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Modules - TypeScript
In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module. Conversely, a file without...
Read more >
Why does this custom type definition not properly export a ...
That package uses CommonJS module.exports syntax to export the function: module.exports = function (str) { ... };.
Read more >
Example of TypeScript Export Function - eduCBA
In TypeScript we can almost export anything using the 'export' keyword. It is not a function rather it can be used to export...
Read more >
How to export a Type in TypeScript | bobbyhadz
Use a named export to export a type in TypeScript, e.g. export type Person = {} . The exported type can be imported...
Read more >
Usage With TypeScript - Redux
Define Slice State and Action Types​. Each slice file should define a type for its initial state value, so that createSlice can correctly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found