我使用React组件的外部库(例如"ui"):
import { Input } from 'ui'
export const LoginForm = () => (
<Input name="login" value={login} />
<Input.Password name="password" value={password} />
)
我有一些类型声明(types/ui.d.ts
):
declare namespace Ui {
export interface InputProps {
value?: string;
}
export class Input extends React.Component<InputProps> {
static Password: any;
}
}
declare module 'ui' {
export import Input = Ui.Input;
}
如何为Input.Password
声明类型?
What I tried:
export class InputPassword extends React.Component<InputPasswordProps> {
// ...
}
declare namespace Ui {
export interface InputProps {
value?: string;
}
export class Input extends React.Component<InputProps> {
static Password: InputPassword;
}
}
但是我得到错误:
JSX element type 'Input.Password' does not have any construct or call signatures.ts(2604)
它适合我:
declare namespace SbolLibUi {
interface InputPasswordProps extends InputPropsBase {
// specific properties
}
interface InputProps extends InputPropsBase {
// specific properties
}
declare class Input extends React.Component<InputProps> {
static readonly Password = class extends React.Component<InputPasswordProps> {
// specific properties
};
}
declare module 'ui' {
export import Input = Ui.Input;
}
}