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

Issues with conditionals.ts #5

Open
tonisives opened this issue Jan 19, 2022 · 1 comment
Open

Issues with conditionals.ts #5

tonisives opened this issue Jan 19, 2022 · 1 comment

Comments

@tonisives
Copy link

I have installed node-fetch dependency. However, the conditionals.ts has an error

Argument of type 'unknown' is not assignable to parameter of type 'PokemonResults'.ts(2345)

Screenshot 2022-01-19 at 17 13 04

The data.json response from the fetch function returns Promise<unknown> type

Fix is to cast data to `Promise

fetch(url)
      .then((data) => data.json() as Promise<PokemonResults>)
      .then((data) => cb(data));

There is also error with fetch.

ts conditionals.ts
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/tonis/workspace/web/ti-no-bs-ts/ts-basics/node_modules/node-fetch/src/index.js from /Users/tonis/workspace/web/ti-no-bs-ts/ts-basics/conditionals.ts not supported.
Instead change the require of index.js in /Users/tonis/workspace/web/ti-no-bs-ts/ts-basics/conditionals.ts to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/tonis/workspace/web/ti-no-bs-ts/ts-basics/conditionals.ts:15:38)
    at Module.m._compile (/Users/tonis/workspace/web/ti-no-bs-ts/ts-basics/node_modules/ts-node/dist/index.js:735:29)
    at Object.require.extensions.<computed> [as .ts] (/Users/tonis/workspace/web/ti-no-bs-ts/ts-basics/node_modules/ts-node/dist/index.js:737:16)
    at main (/Users/tonis/workspace/web/ti-no-bs-ts/ts-basics/node_modules/ts-node/dist/bin.js:238:16)
    at Object.<anonymous> (/Users/tonis/workspace/web/ti-no-bs-ts/ts-basics/node_modules/ts-node/dist/bin.js:351:5) {
  code: 'ERR_REQUIRE_ESM'
}

The solution is to downgrade fetch to v2. link. yarn add node-fetch adds v3 automatically

@Lam-Big-Water
Copy link

Thank you so much!

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

2 participants