【问题标题】:Typescript error: "[ts] Property 'existingProperty' does not exist on type '{}'."打字稿错误:“[ts] 属性‘existingProperty’在类型‘{}’上不存在。”
【发布时间】:2018-11-30 10:02:08
【问题描述】:

检查了这些链接:

  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 中声明的类型中受益。

【问题讨论】:

    标签: typescript react-native


    【解决方案1】:

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

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

    【讨论】:

    • @types/react 完成了这项工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 2017-03-02
    • 2021-09-07
    相关资源
    最近更新 更多