The Joat
The Joat

Reputation: 51

Typescript error: "[ts] Property 'existingProperty' does not exist on type '{}'."

Checked these links:

  1. Typescript error Property does not exist on type
  2. property then does not exist on type void , A typescript error
  3. Typescript property does not exist on type {}
  4. TypeScript: suppress Property does not exist on type
  5. TS2339: Property does not exist on type
  6. https://github.com/Microsoft/TypeScript/issues/1574

But I couldn't seem to understand this behavior.

Reproduce:

git clone https://github.com/the-joat/rn-maps-ts-bug-demo
cd rn-maps-ts-bug-demo
yarn
yarn build

Typescript will successfully compile but I want to suppress the error you'll see in Qwerty.tsx.

I've tried having a .d.ts file that has:

import MapView from "react-native-maps"
declare module "react-native-maps" {
  const a: any
  export default a
}

but it's throwing another error and I don't think it's really a permanent solution since I won't be able to benefit from the types declared in react-native-maps.

Upvotes: 3

Views: 1381

Answers (2)

Wadkan
Wadkan

Reputation: 176

I also faced this issue. For me, the problem was that I used:

<script lang="ts">

but, Composition API style. The correct one should be:

<script setup lang="ts">

(The "setup" part was missing.)

Upvotes: 0

kingdaro
kingdaro

Reputation: 12018

It looks like the react and react-native type definitions are missing from the project. Those types are required to properly recognize the props of JSX elements. Try installing them:

yarn add --dev @types/react @types/react-native

Upvotes: 1

Related Questions