TypeScript workaround for rest props in React

前端 未结 6 773
迷失自我
迷失自我 2021-02-06 22:50

Updated for TypeScript 2.1

TypeScript 2.1 now supports object spread/rest, so no workarounds are needed anymore!


Original Question

TypeScript s

6条回答
  •  灰色年华
    2021-02-06 23:17

    use ...rest

    type ButtonProps = {
        disabled: boolean;
    };
    
    function Button(props: ButtonProps): JSX.Element {
        const {disabled = false, ...rest} = props;
    ...
    return (
        

提交回复
热议问题