Open OliverJAsh opened 6 years ago
Re. https://github.com/gcanti/typelevel-ts/blob/e1d718db887476f7b6b6e2c88542cc6ce3bd8265/examples/withDefaults.tsx
I have a use case for withDefaults that doesn't appear to work, but I'm not entirely clear why.
withDefaults
type Props = | { tag: 'a'; href: string; } | { tag: 'button'; }; declare const props: Props; type DefaultProps = { tag: 'a'; }; declare const defaultProps: DefaultProps; declare function withDefaults<Props extends DefaultProps, DefaultProps extends object>( props: Props, defaultProps: DefaultProps, ): void; withDefaults( // Type '"button"' is not assignable to type '"a"'. props, defaultProps, );
My thinking:
DefaultProps
defaultProps
Props
props
Props extends DefaultProps
Any thoughts?
Re. https://github.com/gcanti/typelevel-ts/blob/e1d718db887476f7b6b6e2c88542cc6ce3bd8265/examples/withDefaults.tsx
I have a use case for
withDefaults
that doesn't appear to work, but I'm not entirely clear why.My thinking:
withDefaults
requiresDefaultProps
(defaultProps
) to be a "supertype" ofProps
(props
) (Props extends DefaultProps
)DefaultProps
is not a supertype ofProps
becauseProps
is a unionAny thoughts?