使用打字稿在应用程序上反应传单

react-leaflet on an application with typescript

我有一个使用 create-react-app 工具创建的 React 应用程序,该应用程序使用 typescript,在导入 create-react-app 和 typescript 库 '@types/leaflet' 之后,我的应用程序失败使用以下错误消息构建:

Failed to compile. 
node_modules/@react-leaflet/core/types/index.d.ts TypeScript error in .../node_modules/@react-leaflet/core/types/index.d.ts(3,1):
Declaration or statement expected.  TS1128

    1 | export { useAttribution } from './attribution';
    2 | export { updateCircle } from './circle';
  > 3 | export type { CircleMarkerProps } from './circle';
      | ^
    4 | export { createContainerComponent, createDivOverlayComponent, createLeafComponent, } from './component';
    5 | export { CONTEXT_VERSION, LeafletContext, LeafletProvider, useLeafletContext, } from './context';
    6 | export type { LeafletContextInterface } from './context';

知道如何解决吗?

我将 package.json 中的 Typescript 版本从 3.4.3 升级到 4.1.2,错误消失了。

我遇到了同样的问题并将其发布在 React-Leaflet 上 GitHub https://github.com/PaulLeCam/react-leaflet/issues/798.

如 Toni Spock 所述,Typescript 版本导致此问题。

问题是 import/export 功能在 Typescript 3.8 之前不可用。所以将 Typescript 版本升级到最新版本应该可以解决这个问题。