Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit a2dcedf

Browse files
luke-johnKent C. Dodds
authored and
Kent C. Dodds
committed
fix(css-properties): remove incorrect React.ReactChild from Lossy Union (#372)
* fix(css-properties): remove incorrect React.ReactChild from Lossy Union This was originally added to fix a problem where built in glamorous components had been typed to accept the css properties union which included the lossy version. By updating that component to instead use the css CompleteSingle interface the React.ReactChild is able to be removed. * chore(typescript): add more test cases for built in components * chore(typescript): update snapshot for new typescript version * chore(typescript): add reported failing Div test case
1 parent b843c27 commit a2dcedf

6 files changed

+1100
-301
lines changed

src/__tests__/__snapshots__/typescript.js.snap

+27-27
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ test/should-fail.test.tsx(135,20): error TS2551: Property 'visibles' does not ex
4545
test/should-fail.test.tsx(140,3): error TS2345: Argument of type '(props: { visible: boolean; } & object) => { display: \\"none\\" | \\"hidden\\"; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, { visible: boolean; } & object>'.
4646
Type '(props: { visible: boolean; } & object) => { display: \\"none\\" | \\"hidden\\"; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, { visible: boolean; } & object>)[]'.
4747
Property 'push' is missing in type '(props: { visible: boolean; } & object) => { display: \\"none\\" | \\"hidden\\"; }'.
48-
test/should-fail.test.tsx(150,29): error TS2322: Type '{ visible: \\"string\\"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<ExampleComponentProps & object & ExtraGl...'.
49-
Type '{ visible: \\"string\\"; }' is not assignable to type 'Readonly<ExampleComponentProps & object & ExtraGlamorousProps>'.
48+
test/should-fail.test.tsx(150,29): error TS2322: Type '{ visible: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<ExampleComponentProps & object & ExtraGl...'.
49+
Type '{ visible: string; }' is not assignable to type 'Readonly<ExampleComponentProps & object & ExtraGlamorousProps>'.
5050
Types of property 'visible' are incompatible.
51-
Type '\\"string\\"' is not assignable to type 'boolean'.
51+
Type 'string' is not assignable to type 'boolean'.
5252
test/should-fail.test.tsx(151,5): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<ExampleComponentProps & object & ExtraGl...'.
5353
Type '{}' is not assignable to type 'Readonly<ExampleComponentProps & object & ExtraGlamorousProps>'.
5454
Property 'visible' is missing in type '{}'.
55-
test/should-fail.test.tsx(152,32): error TS2322: Type '{ visible: \\"string\\"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & { visible: b...'.
56-
Type '{ visible: \\"string\\"; }' is not assignable to type 'Readonly<HTMLProps<HTMLDivElement> & { visible: boolean; } & object & ExtraGlamorousProps>'.
55+
test/should-fail.test.tsx(152,32): error TS2322: Type '{ visible: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & { visible: b...'.
56+
Type '{ visible: string; }' is not assignable to type 'Readonly<HTMLProps<HTMLDivElement> & { visible: boolean; } & object & ExtraGlamorousProps>'.
5757
Types of property 'visible' are incompatible.
58-
Type '\\"string\\"' is not assignable to type 'boolean'.
58+
Type 'string' is not assignable to type 'boolean'.
5959
test/should-fail.test.tsx(153,5): error TS2322: Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & { visible: b...'.
6060
Type '{}' is not assignable to type 'Readonly<HTMLProps<HTMLDivElement> & { visible: boolean; } & object & ExtraGlamorousProps>'.
6161
Property 'visible' is missing in type '{}'.
62-
test/should-fail.test.tsx(157,21): error TS2345: Argument of type '{ allowReorder: false; }' is not assignable to parameter of type 'StyleArgument<SVGProperties, object & {}>'.
63-
Type '{ allowReorder: false; }' is not assignable to type '(string | SVGProperties | StyleFunction<SVGProperties, object & {}>)[]'.
64-
Property 'length' is missing in type '{ allowReorder: false; }'.
62+
test/should-fail.test.tsx(157,21): error TS2345: Argument of type '{ allowReorder: boolean; }' is not assignable to parameter of type 'StyleArgument<SVGProperties, object & {}>'.
63+
Type '{ allowReorder: boolean; }' is not assignable to type '(string | SVGProperties | StyleFunction<SVGProperties, object & {}>)[]'.
64+
Property 'length' is missing in type '{ allowReorder: boolean; }'.
6565
test/should-fail.test.tsx(158,18): error TS2345: Argument of type '{ color: boolean; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, object & {}>'.
6666
Type '{ color: boolean; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, object & {}>)[]'.
6767
Property 'length' is missing in type '{ color: boolean; }'.
@@ -81,21 +81,21 @@ test/should-fail.test.tsx(224,3): error TS2345: Argument of type '(props: { visi
8181
test/should-fail.test.tsx(229,1): error TS2554: Expected 1 arguments, but got 0.
8282
test/should-fail.test.tsx(230,30): error TS2345: Argument of type '\\"\\"' is not assignable to parameter of type 'object'.
8383
test/should-fail.test.tsx(231,30): error TS2345: Argument of type 'false' is not assignable to parameter of type 'object'.
84-
test/should-fail.test.tsx(257,19): error TS2559: Type '{ d: \\"\\"; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & Partial<{ pr...'.
85-
test/should-fail.test.tsx(258,19): error TS2322: Type '{ primaryColor: 1; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & Partial<{ pr...'.
86-
Type '{ primaryColor: 1; }' is not assignable to type 'Readonly<HTMLProps<HTMLDivElement> & Partial<{ primaryColor: string; }> & Pick<{ theme?: any; }, ...'.
84+
test/should-fail.test.tsx(257,19): error TS2559: Type '{ d: string; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & Partial<{ pr...'.
85+
test/should-fail.test.tsx(258,19): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & Partial<{ pr...'.
86+
Type '{ primaryColor: number; }' is not assignable to type 'Readonly<HTMLProps<HTMLDivElement> & Partial<{ primaryColor: string; }> & Pick<{ theme?: any; }, ...'.
8787
Types of property 'primaryColor' are incompatible.
88-
Type '1' is not assignable to type 'string | undefined'.
89-
test/should-fail.test.tsx(259,31): error TS2559: Type '{ d: \\"\\"; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Partial<{ primaryColor: string; }> & Pic...'.
90-
test/should-fail.test.tsx(260,31): error TS2322: Type '{ primaryColor: 1; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Partial<{ primaryColor: string; }> & Pic...'.
91-
Type '{ primaryColor: 1; }' is not assignable to type 'Readonly<Partial<{ primaryColor: string; }> & Pick<{ theme: any; }, never> & ExtraGlamorousProps>'.
88+
Type 'number' is not assignable to type 'string | undefined'.
89+
test/should-fail.test.tsx(259,31): error TS2559: Type '{ d: string; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Partial<{ primaryColor: string; }> & Pic...'.
90+
test/should-fail.test.tsx(260,31): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<Partial<{ primaryColor: string; }> & Pic...'.
91+
Type '{ primaryColor: number; }' is not assignable to type 'Readonly<Partial<{ primaryColor: string; }> & Pick<{ theme: any; }, never> & ExtraGlamorousProps>'.
9292
Types of property 'primaryColor' are incompatible.
93-
Type '1' is not assignable to type 'string | undefined'.
94-
test/should-fail.test.tsx(261,31): error TS2559: Type '{ d: \\"\\"; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & Partial<{ primaryColor: string;...'.
95-
test/should-fail.test.tsx(262,31): error TS2322: Type '{ primaryColor: 1; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & Partial<{ primaryColor: string;...'.
96-
Type '{ primaryColor: 1; }' is not assignable to type 'Readonly<object & Partial<{ primaryColor: string; }> & ExtraGlamorousProps>'.
93+
Type 'number' is not assignable to type 'string | undefined'.
94+
test/should-fail.test.tsx(261,31): error TS2559: Type '{ d: string; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & Partial<{ primaryColor: string;...'.
95+
test/should-fail.test.tsx(262,31): error TS2322: Type '{ primaryColor: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & Partial<{ primaryColor: string;...'.
96+
Type '{ primaryColor: number; }' is not assignable to type 'Readonly<object & Partial<{ primaryColor: string; }> & ExtraGlamorousProps>'.
9797
Types of property 'primaryColor' are incompatible.
98-
Type '1' is not assignable to type 'string | undefined'.
98+
Type 'number' is not assignable to type 'string | undefined'.
9999
test/should-fail.test.tsx(267,15): error TS2345: Argument of type '{ textAlign: \\"center\\"; display: (\\"block\\" | \\"flexs\\")[]; }' is not assignable to parameter of type 'StyleArgument<CSSProperties, {}>'.
100100
Type '{ textAlign: \\"center\\"; display: (\\"block\\" | \\"flexs\\")[]; }' is not assignable to type '(string | CSSProperties | StyleFunction<CSSProperties, {}>)[]'.
101101
Property 'length' is missing in type '{ textAlign: \\"center\\"; display: (\\"block\\" | \\"flexs\\")[]; }'.
@@ -105,14 +105,14 @@ test/should-fail.test.tsx(272,18): error TS2345: Argument of type '{ textAlign:
105105
test/should-fail.test.tsx(289,35): error TS2322: Type '{ display: \\"blocks\\"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & CSSProperties & ExtraGlamorousP...'.
106106
Type '{ display: \\"blocks\\"; }' is not assignable to type 'Readonly<object & CSSProperties & ExtraGlamorousProps>'.
107107
Types of property 'display' are incompatible.
108-
Type '\\"blocks\\"' is not assignable to type '\\"none\\" | \\"table\\" | \\"ruby\\" | \\"initial\\" | \\"inherit\\" | \\"unset\\" | \\"block\\" | \\"inline\\" | \\"run-in\\" | \\"fl...'.
109-
test/should-fail.test.tsx(290,38): error TS2559: Type '{ display: \\"block\\"; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & ExtraGlamorousProps, ComponentS...'.
110-
test/should-fail.test.tsx(291,42): error TS2559: Type '{ display: \\"block\\"; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & ExtraGlamorousProps, ComponentS...'.
108+
Type '\\"blocks\\"' is not assignable to type '\\"none\\" | \\"ruby\\" | \\"table\\" | \\"inline\\" | \\"grid\\" | \\"initial\\" | \\"inherit\\" | \\"unset\\" | \\"block\\" | \\"run-...'.
109+
test/should-fail.test.tsx(290,38): error TS2559: Type '{ display: string; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & ExtraGlamorousProps, ComponentS...'.
110+
test/should-fail.test.tsx(291,42): error TS2559: Type '{ display: string; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<object & ExtraGlamorousProps, ComponentS...'.
111111
test/should-fail.test.tsx(293,29): error TS2322: Type '{ display: \\"blocks\\"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & object & CSS...'.
112112
Type '{ display: \\"blocks\\"; }' is not assignable to type 'Readonly<HTMLProps<HTMLDivElement> & object & CSSProperties & ExtraGlamorousProps>'.
113113
Types of property 'display' are incompatible.
114-
Type '\\"blocks\\"' is not assignable to type '\\"none\\" | \\"table\\" | \\"ruby\\" | \\"initial\\" | \\"inherit\\" | \\"unset\\" | \\"block\\" | \\"inline\\" | \\"run-in\\" | \\"fl...'.
115-
test/should-fail.test.tsx(294,32): error TS2559: Type '{ display: \\"block\\"; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & object & Ext...'.
116-
test/should-fail.test.tsx(295,36): error TS2559: Type '{ display: \\"block\\"; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & object & Ext...'.
114+
Type '\\"blocks\\"' is not assignable to type '\\"none\\" | \\"ruby\\" | \\"table\\" | \\"inline\\" | \\"grid\\" | \\"initial\\" | \\"inherit\\" | \\"unset\\" | \\"block\\" | \\"run-...'.
115+
test/should-fail.test.tsx(294,32): error TS2559: Type '{ display: string; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & object & Ext...'.
116+
test/should-fail.test.tsx(295,36): error TS2559: Type '{ display: string; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<HTMLProps<HTMLDivElement> & object & Ext...'.
117117
"
118118
`;

test/glamorous.test.tsx

+68-6
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ const pureDivFactory2 = glamorous<ShouldClassNameUpdateProps, ShouldClassNameUpd
473473
},
474474
})
475475

476-
const Div = pureDivFactory({marginLeft: 1})
476+
const PureDiv = pureDivFactory({marginLeft: 1})
477477

478478
// withProps
479479

@@ -534,17 +534,26 @@ const usePropsAreCssOverrides = (
534534
</div>
535535
)
536536

537-
const BuiltinSingleElement: JSX.Element = <glamorous.Div />;
537+
import { Span, Div } from "../"
538+
539+
const testDiv: React.ReactNode = (
540+
<Div>
541+
<Div />
542+
</Div>
543+
)
544+
545+
const BuiltinSingleElement: JSX.Element = <glamorous.Div display="block" onClick={() => {}} />;
546+
const BuiltinSingleElementNamedExport: JSX.Element = <Span display="block" onClick={() => {}} />;
538547

539548
const BuiltinSingleChild: JSX.Element = (
540549
<glamorous.Div>
541-
<glamorous.Span>Hello, world!</glamorous.Span>
550+
<Span>Hello, world!</Span>
542551
</glamorous.Div>
543552
);
544553

545554
const BuiltinMultipleChild: JSX.Element = (
546555
<glamorous.Div>
547-
<glamorous.Span>Hello,</glamorous.Span>
556+
<Span>Hello,</Span>
548557
<glamorous.Span>world!</glamorous.Span>
549558
</glamorous.Div>
550559
);
@@ -559,8 +568,61 @@ const BuiltinStyledWithSingleChild: JSX.Element = (
559568
);
560569

561570
const BuiltinStyledWithMultipleChild: JSX.Element = (
562-
<glamorous.Div color='red'>
571+
<glamorous.Div color='red' onClick={() => {}}>
563572
<glamorous.Span>Hello,</glamorous.Span>
564-
<glamorous.Span>world!</glamorous.Span>
573+
<Span>world!</Span>
574+
</glamorous.Div>
575+
);
576+
577+
const CustomStatelessComponent: React.SFC<{}> = (_props) => <div />
578+
class CustomClassComponent extends React.Component<{}, {}> {
579+
render() {
580+
return null
581+
}
582+
}
583+
const CustomGlamorousComponent = glamorous.div()
584+
const CustomGlamorousComponent2 = glamorous('div')()
585+
const CustomGlamorousComponent3 = glamorous(CustomGlamorousComponent)()
586+
const BuiltinStyledComponentChildren: JSX.Element = (
587+
<glamorous.Div height={18} onClick={() => {}}>
588+
{}
589+
<CustomStatelessComponent />
590+
<CustomClassComponent />
591+
<CustomGlamorousComponent />
592+
<CustomGlamorousComponent2 />
593+
<CustomGlamorousComponent3 />
565594
</glamorous.Div>
595+
)
596+
const BuiltinStyledWithPrimitivesChildren: JSX.Element = (
597+
<PureDiv color='red'>
598+
{null}
599+
{false}
600+
{true}
601+
{undefined}
602+
{5}
603+
</PureDiv>
604+
);
605+
606+
const BuiltinStyledWithFragment: JSX.Element = (
607+
<div>
608+
<glamorous.Div color='red' onClick={() => {}}>
609+
<React.Fragment />
610+
</glamorous.Div>
611+
<Span color='red' onClick={() => {}}>
612+
<React.Fragment />
613+
</Span>
614+
</div>
615+
);
616+
617+
const cssProps = {
618+
":active": {
619+
color: "purple"
620+
}
621+
};
622+
623+
const BuiltinStyledWithCSSPseudoProps = (
624+
<div>
625+
<glamorous.A {...cssProps} />
626+
<glamorous.A css={cssProps} />
627+
</div>
566628
);

0 commit comments

Comments
 (0)