Javascript 在Typescript中,我将如何键入此';撰写';功能

Javascript 在Typescript中,我将如何键入此';撰写';功能,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,我正在将我的Javascript库转换为Typescript(到目前为止我所做的工作位于分支上),但我很难键入这个compose函数(当然,还有一些其他可组合函数,但现在是…): 基本用法: const componedstyledcomponent=compose.t(fn,fn,fn,…等)` s ` 细分: compose takes 3 args: t(ag) = single HTML Element as property of compose or passed as (&quo

我正在将我的Javascript库转换为Typescript(到目前为止我所做的工作位于分支上),但我很难键入这个
compose
函数(当然,还有一些其他可组合函数,但现在是…):

基本用法:

const componedstyledcomponent=compose.t(fn,fn,fn,…等)`
s
`
细分:

compose takes 3 args:
t(ag) = single HTML Element as property of compose or passed as ("string")
f(unctions) = composable functions (withProps(...), withStyles(...), ...etc)  -- see below for full list
s(tyles) = 
   either template literal CSS Properties:
  ` background: ${props => props.primary ? "blue" : "red" }; ` 
   
   or can be an object of CSS Properties: 
   { background: ${props => props.primary ? "blue" : "red" };
我目前拥有的:

import styled,{css}来自“styled components”;
从“./domElements”//[“a”、“缩写”、“地址”、“区域”等]
从“./types”导入{ComponentType};
//这需要限制为任何这些可组合函数的单一使用:
//setDisplayName、withAttributes、withDefaultProps、withProps、withPropTypes、withStyles
类型函数=任意[];
常量扩展=(…f:函数)=>
f、 减少(
(a,b)=>(…args)=>a(b(…args)),
arg=>arg
);
//可以是字符串:compose.div | compose(“div”)
//或
//它可以是React样式的组件:compose(按钮)
类型标记=字符串|组件类型


任何帮助都将不胜感激。

看看他们是如何实现styled的:

// 'const styled' is an implementation of this with defaults set
export interface ThemedBaseStyledInterface<T extends object>
    extends ThemedStyledComponentFactories<T> {
    <C extends AnyStyledComponent>(component: C): ThemedStyledFunction<
        StyledComponentInnerComponent<C>,
        T,
        StyledComponentInnerOtherProps<C>,
        StyledComponentInnerAttrs<C>
    >;
    <C extends keyof JSX.IntrinsicElements | React.ComponentType<any>>(
        // unfortunately using a conditional type to validate that it can receive a `theme?: Theme`
        // causes tests to fail in TS 3.1
        component: C
    ): ThemedStyledFunction<C, T>;
}
/'const styled'是此方法的一个实现,设置了默认值
导出接口BaseStyledInterface
扩展主题样式组件工厂{
(组件:C):主题样式函数<
StyledComponentAnnerComponent,
T
StyledComponentNetherProps,
样式组件连接器
>;
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '(t: Tag) => (...f: Functions) => (...s: Styles[]) => any'.
  No index signature with a parameter of type 'string' was found on type '(t: Tag) => (...f: Functions) => (...s: Styles[]) => any'.
// 'const styled' is an implementation of this with defaults set
export interface ThemedBaseStyledInterface<T extends object>
    extends ThemedStyledComponentFactories<T> {
    <C extends AnyStyledComponent>(component: C): ThemedStyledFunction<
        StyledComponentInnerComponent<C>,
        T,
        StyledComponentInnerOtherProps<C>,
        StyledComponentInnerAttrs<C>
    >;
    <C extends keyof JSX.IntrinsicElements | React.ComponentType<any>>(
        // unfortunately using a conditional type to validate that it can receive a `theme?: Theme`
        // causes tests to fail in TS 3.1
        component: C
    ): ThemedStyledFunction<C, T>;
}
class MyButton extends React.Component<ButtonProps> {
    render() {
        return <button>Custom button</button>;
    }
}

const TomatoButton = styled(MyButton)`
    color: tomato;
    border-color: tomato;
`;
// Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background
const Wrapper = styled.section`
    padding: 4em;
    background: papayawhip;
`;