Definitelytyped: [@types/react-native] Property 'geolocation' must be of type 'Geolocation', but here has type 'GeolocationStatic'.

Created on 28 Mar 2018  路  26Comments  路  Source: DefinitelyTyped/DefinitelyTyped

If you know how to fix the issue, make a pull request instead.

  • [x] I tried using the @types/react-native package and had problems.
  • [x] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [x] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [x] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @alloy @huhuanming @iRoachie @timwangdev @kamal @nelyousfi

I started a brand new project, installed the newest versions and when I try to compile it gives this error:

node_modules/@types/react-native/index.d.ts(8731,18): error TS2717: Subsequent property declarations must have the same type. Property 'geolocation' must be of type 'Geolocation', but here has type 'GeolocationStatic'.

My dependencies are:

"dependencies": {
"react": "^16.2.0",
"react-native": "^0.54.3"
},
"devDependencies": {
"@ types/react": "^16.1.0",
"@ types/react-native": "^0.52.20",
"concurrently": "^3.5.1",
"rimraf": "^2.6.2",
"tslib": "^1.9.0",
"typescript": "^2.8.1"
}

os: Windows 10
node: v8.2.1

Most helpful comment

As a temporary workaround set skipLibCheck to true in your tsconfig

All 26 comments

As a temporary workaround set skipLibCheck to true in your tsconfig

downgrade typescript to '2.7.1' fixed it

remove dom types from tsconfig should bypass this.

@timwangdev If I remove dom from libs, then many types will be undefined, e.g. FormData, XMLHttpRequest, ProgressEvent, WebSocket, ...
So, also I think it right direction to do, this is not solution currently. We should first add full RN environment in react-native.d.ts

Does anyone have a clue about how to correctly fix the error without use skipLibCheck ?
I can take time to make the PR.

@VincentLanglet [email protected] lib.dom.d.ts declare Geolocation, but @types/react-native also declare Geolocation too.

Currently using workaround via removing from react native via patch-package https://github.com/ds300/patch-package

Thanks @chrisbenincasa, doing what @AbelHuai suggested fixed the issue for me:

  • Downgrade TypeScript to version 2.7.2 ("typescript": "2.7.2" in packages.json)
    or
  • Add "skipLibCheck": true to tsconfig.json

further to @tonyxiao 's comment, the following patch works:

patch-package
--- a/node_modules/@types/react-native/index.d.ts
+++ b/node_modules/@types/react-native/index.d.ts
@@ -8533,8 +8533,9 @@ export type Clipboard = ClipboardStatic;
 export var DatePickerAndroid: DatePickerAndroidStatic;
 export type DatePickerAndroid = DatePickerAndroidStatic;

-export var Geolocation: GeolocationStatic;
-export type Geolocation = GeolocationStatic;
+// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/24573
+// export var Geolocation: GeolocationStatic;
+// export type Geolocation = GeolocationStatic;

 /** http://facebook.github.io/react-native/blog/2016/08/19/right-to-left-support-for-react-native-apps.html */
 export var I18nManager: I18nManagerStatic;

I am having the same issue but unfortunately the error persists with either (or both) "typescript": "2.7.2" and "skipLibCheck": true:

My dependencies:

 "dependencies": {
    "@types/jest": "^22.2.0",
    "@types/react": "^16.3.13",
    "@types/react-native": "^0.52.16",
    "concurrently": "^3.5.1",
    "react": "^16.3.2",
    "react-art": "16.3.2",
    "react-dom": "^16.3.2",
    "react-native": "0.55.0",
    "react-native-scripts": "1.14.0",
    "react-native-web": "0.6.0",
    "react-scripts": "1.1.4",
    "typescript": "^2.7.2"
  },

What am I missing? I also could not find which versions of @types are recommended with which versions of the actual libraries.

Thanks for you help!

skipLibCheck: true worked for our repo, however I'm subscribing to this thread so I hear when it's fixed in @types/react-native 馃槈

Please people DO NOT 馃敶 use "skipLibCheck": true it your tsconfig.json file! It will make your TypeScript less useful!

The problem in this case is that BOTH dom and react-native types have global Navigator object. This is correct BUT TypeScript added geolocation object to Navigator object between TS version 2.7.2 and 2.8.1 in this commit. So now when BOTH dom and react-native are trying to set different type for geolocation object inside of Navigation the whole thing breaks 鈿狅笍

I honestly don't know solution for this problem at the moment. This is because react-native types depends on dom types. So you can't take dom types away from your project. But at the same time you can't type globally marked object's properties to different type later 馃槩

The problem is now debugged but now we need more help to get proper solution.

How does skipLibCheck make typescript less useful?

@iRoachie If you use any types from definitions which are broken, certain parts of those APIs will return and accept any. If you run type checks are part of CI to increase your confidence that your program will run and reduce the amount of debugging to trace down issues, any code using such APIs will not be marked as incorrect by TypeScript. You will not know that this is happening if you enable skipLibCheck.

Am I still only one trying to solve this? 馃

I can't think of any other solution that React Native should move their geolocation api as import and not global. This way we can type the exported navigator anything we want. But this requires JS changes and it will be breaking change

I have made possible solution for this in this PR: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/27436 馃帀

Looks like the solution is to

  1. remove dom from lib array at tsconfig.json file.
  2. update @types/react-native to 0.56.4
  3. fix compile errors
  4. profit! 馃帀

@henrikra Does this require updating react-native to 0.56.x ? or just update the type definition.

No it requires only to update the types like I wrote ;)

Do you maybe have a sample tsconfig.json for a react-native project? @henrikra I'm pretty new to typescript and i can't seem to figure out how to remove "dom" from the lib array since it is part of most lib config.

@seanyu4296 You can follow the steps in this guide https://github.com/ds300/react-native-typescript-transformer

thank you @iRoachie im currently using that right now and its working. Not sure if this is the right place to ask but i noticed when i used the tsc in vscode it does not work. Is it possible to configure vscode to use react native ts transformer?

I didn't have to do any additional setup with VSCode. What issues are you having?

@luizvidoto This can be closed btw

@henrikra Thanks, I鈥檒l do so now 馃憤

Was this page helpful?
0 / 5 - 0 ratings