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

Typescript 4.1.2 fails with "Cannot find name 'PositionError'" #1646

Closed
syabro opened this issue Nov 20, 2020 · 16 comments
Closed

Typescript 4.1.2 fails with "Cannot find name 'PositionError'" #1646

syabro opened this issue Nov 20, 2020 · 16 comments
Labels

Comments

@syabro
Copy link

syabro commented Nov 20, 2020

What is the current behavior?
I've got an error

node_modules/react-use/lib/useGeolocation.d.ts(11,21): error TS2304: Cannot find name 'PositionError'.

react-use: 15.3.4
typescript: 4.1.2

@dovidweisz
Copy link
Contributor

I'm running into the same issue.

My node_modules folder is listed in my tsconfig excludes

I also tied adding:

node_modules
node_modules/react-use
node_modules/react-use/lib/useGeolocation.d.ts

still failing

@dovidweisz
Copy link
Contributor

I just wonder if maybe this is an issue with TypeScript and not with the types.

@dovidweisz
Copy link
Contributor

It seems like PositionError was changed to GeolocationPositionError in this version of Typescript.

@dovidweisz
Copy link
Contributor

dovidweisz commented Nov 24, 2020

The fix itself is easy, and I would gladly do a PR for it. The issue is backwards compatibility with older versions of Typescript.

I did a little research and there doesn't seem to be a good solution to this problem.

For the time being i created a patch and am running it postinstall.

Here's the patch (it's not that pretty, but it should work):
https://gist.github.com/dovidweisz/4d76168339db89cf05e1090a84b7ee41

Never mind the patch. @ileonovdima 's idea is much better.

@giogonzo
Copy link

@dovidweisz typesVersions could help here?

@ileonovdima
Copy link

ileonovdima commented Nov 25, 2020

solved the problem by adding in global.d.ts

type PositionError = GeolocationPositionError;

@dovidweisz
Copy link
Contributor

dovidweisz commented Nov 25, 2020

@dovidweisz typesVersions could help here?

@giogonzo: Cool, I didn't know that was available. (I wonder how it would be implemented)

solved the problem by adding in global.d.ts

type PositionError = GeolocationPositionError;

@ileonovdima: Super cool TYVM

I love the way I have that "Contributor" badge here. I literally changed a few characters... Once... IN THE DOCS.

LOL

@giogonzo
Copy link

@dovidweisz basically producing 2 different outputs (e.g. one in lib and one in lib4.1) and applying your patch only on lib4.1 (and pointing TS to the correct folder via that key in package.json)

@dovidweisz
Copy link
Contributor

dovidweisz commented Nov 26, 2020

@dovidweisz basically producing 2 different outputs (e.g. one in lib and one in lib4.1) and applying your patch only on lib4.1 (and pointing TS to the correct folder via that key in package.json)

Hmmmm

Seems doable, but I would flip that around. I would:

  1. Upgrade the library to the latest version of Typescript.
  2. Add a build step that copies the d.ts into a ts4.0 directory, and...
  3. Applies the reverse of my patch with a simple string replacement (src.replace("GeolocationPositionError", "PositionError")) to the original files.

I'm looking for other projects with the same (or similar) issues. I guess any front end project that is built in Typescript, and uses typesVersions.

@giogonzo
Copy link

Seems doable, but I would flip that around

I agree 👍

@ranisalt
Copy link

solved the problem by adding in global.d.ts

Where should this file go? I tried several places and typescript doesn't seem to pick it up.

@ValentinH
Copy link

solved the problem by adding in global.d.ts

Where should this file go? I tried several places and typescript doesn't seem to pick it up.

Same here

@dovidweisz
Copy link
Contributor

dovidweisz commented Dec 11, 2020 via email

@cliffordfajardo
Copy link

I'm also getting this with typescript v4.1.3

@dovidweisz dovidweisz mentioned this issue Jan 7, 2021
13 tasks
@xobotyi
Copy link
Contributor

xobotyi commented Jan 8, 2021

@dovidweisz made a bit overkill the easiest way is to introduce own interface compatible with GeolocationPositionError

@xobotyi xobotyi closed this as completed in ebc7094 Jan 8, 2021
xobotyi added a commit that referenced this issue Jan 8, 2021
streamich pushed a commit that referenced this issue Jan 8, 2021
## [15.3.7](v15.3.6...v15.3.7) (2021-01-08)

### Bug Fixes

* [#1646](#1646) ([ebc7094](ebc7094))
@streamich
Copy link
Owner

🎉 This issue has been resolved in version 15.3.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

eaglus pushed a commit to eaglus/react-use that referenced this issue Jan 21, 2021
make own interface that compatible with GeolocationPositionError and PositionError.

It is the easiest way to avoid errors in typescript 4.1
eaglus pushed a commit to eaglus/react-use that referenced this issue Jan 21, 2021
kamranayub pushed a commit to kamranayub/react-use that referenced this issue May 28, 2021
make own interface that compatible with GeolocationPositionError and PositionError.

It is the easiest way to avoid errors in typescript 4.1
kamranayub pushed a commit to kamranayub/react-use that referenced this issue May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants