【发布时间】:2019-02-22 19:22:33
【问题描述】:
是否可以重新导出现有的类型化模块并将其类型用于非类型化模块?
我正在导入一个库 react-final-form-html5-validation,它只是键入 react-final-form 的一个小包装。
有什么选择吗?
我已经尝试了很多很多东西.......,但这看起来最有希望,但是,react-final-form 没有声明命名空间,所以我不能像使用下面的 React 那样使用它的类型.
project/index.d.ts
/// <reference types="react-final-form" />
//// <reference types="./node_modules/react-final-form/dist/index.d.ts" />
//// <reference path="./node_modules/react-final-form/dist/index.d.ts" />
//// <amd-dependency path="./node_modules/react-final-form/dist/index.d.ts" />
// importing resolves the types, but also turns it into a module, which in turn breaks it
// import * as RFF from react-final-form;
// import { FieldProps } from react-final-form;
// export * from react-final-form;
declare module 'react-final-form-html5-validation' {
var Field: React.ComponentType<FieldProps>
}
project/src/index.tsx
import { Field, Abc } from 'react-final-form-html5-validation'
// correct: Module '"react-final-form-html5-validation"' has no exported member 'Abc'
// later in App.render() { return ( .....
<Field />
// Field is of type React.ComponentType<any>
【问题讨论】: