打字稿错误:“ [ts]类型'{}'上不存在属性'existingProperty'。”

时间:2018-06-21 07:01:19

标签: typescript react-native

检查了以下链接:

  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

但是我似乎无法理解这种行为。

复制:

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

Typescript将成功编译,但我想消除在Qwerty.tsx中看到的错误。

我尝试过一个.d.ts文件,该文件具有:

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

但是它引发了另一个错误,并且我认为它不是永久解决方案,因为我将无法从react-native-maps中声明的类型中受益。

1 个答案:

答案 0 :(得分:1)

项目中似乎缺少react和react-native类型定义。这些类型是正确识别JSX元素的属性所必需的。尝试安装它们:

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