react-boostrap-typeahead的自定义Typescript定义
Custom Typescript Definition for react-boostrap-typeahead
我试图为react-bootstrap-typeahead创建一个自定义的Typescript定义。到目前为止,以下是我根据文档编写的内容:
// Custom made typings based on exampes: https://github.com/ericgio/react-bootstrap-typeahead
declare namespace ReactBootstrapTypeahead {
import React = __React;
// Input
class ReactBootstrapTypeahead extends React.Component<ReactBootstrapTypeaheadProps, any> {
}
interface ReactBootstrapTypeaheadProps extends React.HTMLProps<ReactBootstrapTypeahead> {
align?: string;
allowNew?: boolean;
defaultSelected?: any[];
disabled?: boolean;
emptyLabel?: string;
labelKey?: string;
maxHeight?: number;
minLength?: number;
multiple?: boolean;
name?: string;
newSelectionPrefix?: string;
onBlur?(): any;
onChange?(): any;
onInputChange?(): any;
options: any[];
paginateResults?: number;
paginationText?: string;
placeholder?: string;
renderMenuItemChildren?(): any;
}
}
declare module 'react-bootstrap-typeahead' {
export = ReactBootstrapTypeahead;
}
当我尝试使用组件时,我得到了几个错误:
Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components).
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
对于Typescript的定义我还是个新手,如果有任何帮助,我将不胜感激。
当您为库编写声明文件时,强烈建议尝试将所有内容包装在模块化声明文件中,而不是全局声明文件中。
我首先拉入react (typings install react --save
)的模块化声明文件。
然后我将修改您的声明文件,以专门从react中拉入类型。
custom-typings/react-bootstrap-typeahead
declare module 'react-bootstrap-typeahead' {
import React = require('react')
interface ReactBootstrapTypeaheadProps extends React.HTMLProps<ReactBootstrapTypeahead> {
// ¯'_(ツ)_/¯
}
class ReactBootstrapTypeahead extends React.Component<ReactBootstrapTypeaheadProps, any> {
}
export = ReactBootstrapTypeahead
}
在项目的任何地方,这应该都可以正常编译
import ReactTypeahead = require('react-bootstrap-typeahead')
相关文章:
- 在gump和nodejs中使用Typescript时,未定义对require和exports的引用
- 为其他JS生成定义“;编译器”;来自TypeScript定义文件
- 如何用Typescript用自定义方法实现类数组
- typescript定义构造函数或函数
- Angular2-TypeError:无法读取属性'Id'(Typescript)中未定义的
- Angular 2中的@Angular包缺少TypeScript类型定义
- 如何存根Typescript接口/类型定义
- TypeScript定义外部类
- Visual Studio 2015 Update 2-'中的TypeScript模块;要求'未定义
- 我是否必须在每个文件中引用 TypeScript 定义
- Typescript和Browserify-未捕获的TypeError:无法读取属性'步骤'的未定义
- Typescript定义:如何在类内部声明类
- 有没有一种简单的方法来安装TypeScript定义
- TypeScript-如何定义具有任何类型参数的函数类型
- NodeJS'到UpperCase'的未定义(从typescript生成)
- TypeScript运行时错误'未定义'
- 运行时未定义Typescript模块
- 如何为函数定义Typescript接口
- 为Magnific Popup定义Typescript文件
- react-boostrap-typeahead的自定义Typescript定义