Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 正在尝试编写类型脚本定义文件—;JSX元素类型';侧菜单';没有任何构造或调用签名_Typescript_React Native - Fatal编程技术网

Typescript 正在尝试编写类型脚本定义文件—;JSX元素类型';侧菜单';没有任何构造或调用签名

Typescript 正在尝试编写类型脚本定义文件—;JSX元素类型';侧菜单';没有任何构造或调用签名,typescript,react-native,Typescript,React Native,我正试图为它编写一个类型定义文件来声明它。我在一个TypeScript项目中使用它,但它没有TypeScript定义 通常对我有效的方法是: declare module 'react-native-side-menu' { export class SideMenu {any} } 这适用于许多其他库,但对于这个库,我得到: $ ./node_modules/.bin/tsc --alwaysStrict --skipLibCheck --watch [12:37:41] File c

我正试图为它编写一个类型定义文件来声明它。我在一个TypeScript项目中使用它,但它没有TypeScript定义

通常对我有效的方法是:

declare module 'react-native-side-menu' {
  export class SideMenu {any}
}
这适用于许多其他库,但对于这个库,我得到:

$ ./node_modules/.bin/tsc --alwaysStrict --skipLibCheck --watch

[12:37:41] File change detected. Starting incremental compilation...

app/views/Movies.tsx:85:8 - error TS2604: JSX element type 'SideMenu' does not have any construct or call signatures.

85       <SideMenu menu={menu}>
          ~~~~~~~~


app/views/Actors.tsx:80:8 - error TS2604: JSX element type 'SideMenu' does not have any construct or call signatures.

80       <SideMenu menu={menu}>
          ~~~~~~~~


[12:37:41] Found 2 errors. Watching for file changes.
$./node\u modules/.bin/tsc--alwaysStrict--skipLibCheck--watch
[12:37:41]检测到文件更改。正在启动增量编译。。。
app/views/Movies.tsx:85:8-错误TS2604:JSX元素类型“SideMenu”没有任何构造或调用签名。
85
~~~~~~~~
app/views/Actors.tsx:80:8-错误TS2604:JSX元素类型“SideMenu”没有任何构造或调用签名。
80
~~~~~~~~
[12:37:41]发现2个错误。监视文件更改。
(我这样使用它:
从“react native side menu”(反应本机端菜单)导入SideMenu
,它在应用程序中正常工作。我只想删除TypeScript错误消息。)


如何使用TypeScript正确声明此模块?

我想我缺少了一个
默认值
(如
导出默认类…
)。我的最终解决方案:

declare module 'react-native-side-menu' {
  import { Component } from 'react'

  export default class SideMenu extends Component<any,any>{any}
}
声明模块“反应本机端菜单”{
从“react”导入{Component}
导出默认类侧菜单扩展组件{any}
}
  • 你不需要
    任何
    在你的类体内。事实上,这将导致一个错误
  • 您不需要类型参数-
    {}
    也是默认值
  • 如果您知道props
    侧菜单接受什么,您可以在声明中描述它们(这里:
    props
  • 反应本机端菜单.d.ts

    declare module 'react-native-side-menu' {
      import { Component } from 'react'
    
      interface Props {}
    
      export default class SideMenu extends Component<Props> {}
    }
    
    声明模块“反应本机端菜单”{
    从“react”导入{Component}
    接口道具{}
    导出默认类侧菜单扩展组件{}
    }