Skip to content

Instantly share code, notes, and snippets.

@3cL1p5e7
Created November 5, 2020 12:18
Show Gist options
  • Save 3cL1p5e7/5529ab48cc0c3429d94dbe32af837399 to your computer and use it in GitHub Desktop.
Save 3cL1p5e7/5529ab48cc0c3429d94dbe32af837399 to your computer and use it in GitHub Desktop.
import styled from 'styled-components';
import { AddComponentProps } from '@midhub/components/dist/utils/AddComponentProps';
// example 1
const TestComponent = <C extends React.ElementType = 'button'>(
p: AddComponentProps<{ text: number }, C>
) => <span>{p.text}</span>;
const TestComponentStyled = styled(TestComponent)``;
// Problem hehe
export const Test1 = () => <TestComponentStyled test='1' text={22} />; // typecheck DOES NOT throws error for `test` property
export const Test2 = () => <TestComponent test='1' text={22} />; // typecheck THROWS error for `test` property
// example 2
const TestComponent2 = (
p: { text: number }
) => <span>{p.text}</span>;
const TestComponentStyled2 = styled(TestComponent2)``;
export const Test3 = () => <TestComponentStyled2 test='1' text={22} />; // typecheck THROWS error for `test` property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment