Skip to content

Commit adabfd2

Browse files
committed
Reorder overloads for styled component creator
Formerly, the first overload to be tried was not accepting template strings array as first argument. Therefore, it couldn't be used when `styled` was used as a tag for template string. So in this case TS skipped this overload and fell through to the next. Now, though, with `ArrayInterpolation` type changed, `TemplateStringsArray` matches the definition of `ArrayInterpolation`; therefore, this overload becomes used for template strings, confusing type inference. This change moves this overload to the end of the list, i.e. to be used as fallback when there's actually a direct function call, without template string.
1 parent c44db7f commit adabfd2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/styled/types/base.d.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,18 @@ export interface CreateStyledComponent<
6363
SpecificComponentProps extends {} = {},
6464
JSXProps extends {} = {}
6565
> {
66+
(
67+
template: TemplateStringsArray,
68+
...styles: Array<
69+
Interpolation<ComponentProps & SpecificComponentProps & { theme: Theme }>
70+
>
71+
): StyledComponent<ComponentProps, SpecificComponentProps, JSXProps>
72+
6673
/**
6774
* @typeparam AdditionalProps Additional props to add to your styled component
6875
*/
69-
<AdditionalProps extends {} = {}>(
76+
<AdditionalProps extends {}>(
77+
template: TemplateStringsArray,
7078
...styles: Array<
7179
Interpolation<
7280
ComponentProps &
@@ -80,18 +88,10 @@ export interface CreateStyledComponent<
8088
JSXProps
8189
>
8290

83-
(
84-
template: TemplateStringsArray,
85-
...styles: Array<
86-
Interpolation<ComponentProps & SpecificComponentProps & { theme: Theme }>
87-
>
88-
): StyledComponent<ComponentProps, SpecificComponentProps, JSXProps>
89-
9091
/**
9192
* @typeparam AdditionalProps Additional props to add to your styled component
9293
*/
93-
<AdditionalProps extends {}>(
94-
template: TemplateStringsArray,
94+
<AdditionalProps extends {} = {}>(
9595
...styles: Array<
9696
Interpolation<
9797
ComponentProps &

0 commit comments

Comments
 (0)