鉴于这些类型:
export type ButtonProps = {
kind?: 'normal' | 'flat' | 'primary';
negative?: boolean;
size?: 'small' | 'big';
spinner?: boolean;
}
export type LinkButtonPropsExtended = ButtonProps & React.HTMLProps<HTMLAnchorElement>;
const LinkButton = ({ children, href, ...rest }: LinkButtonPropsExtended) => (
<a href={href} className={cls(rest)}>
{ children }
</a>
);
这个用例是怎么来的:
<LinkButton href={url} size="big">My button</LinkButton>
抛出这种类型的错误:
64:53 Type 'string' is not assignable to type 'undefined'.
63 | <Button size="big">Another button<Button>
> 64 | <LinkButton href={url} size="big">My button</LinkButton>
| ^
Typescript 编译器是否将 prop 解释size
为类型undefined
?为什么?