正确注释与打字稿反应的HOC

时间:2019-11-09 09:15:20

标签: reactjs typescript higher-order-components

我在正确注释以下HOC时遇到困难。我不知道该为函数的返回类型添加什么,也不知道如何为道具添加注释。我总是出错。

- (BOOL)growingTextView:(HPGrowingTextView *)growingTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

    NSString* fullText = [growingTextView.text stringByReplacingCharactersInRange:range withString:text];
    growingTextView.internalTextView.typingAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:[UIColor whiteColor]};

    return YES;
}

有人知道如何解决这个问题吗?帮助将不胜感激!

1 个答案:

答案 0 :(得分:1)

在打字稿中指定任何匿名函数表达式的返回类型的正确方法如下。类型说明位于参数声明

之后
const withAuthentication = (
    Component: React.ComponentType<Props>
) : React.Component<Props> => {
    const WithAuthentication = (props: Any) => {
        const { firebase } = props;

        return (
            <AuthUserContext.Provider value={authenticated}>
                <Component {...(props as Props)} />
            </AuthUserContext.Provider>
        );
    };

    return withFirebase(WithAuthentication);
};