File tree Expand file tree Collapse file tree 4 files changed +38
-10
lines changed
Expand file tree Collapse file tree 4 files changed +38
-10
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
1212
1313### Bug fixes
1414
15+ - Worked around issue where TypeScript will not generate correct types for functional components that have subcomponents ([ #2111 ] ( https://github.com/Shopify/polaris-react/pull/2111 ) )
16+
1517### Documentation
1618
1719### Development workflow
Original file line number Diff line number Diff line change @@ -38,7 +38,15 @@ export interface AutocompleteProps {
3838 onLoadMoreResults ?( ) : void ;
3939}
4040
41- export function Autocomplete ( {
41+ // TypeScript can't generate types that correctly infer the typing of
42+ // subcomponents so explicitly state the subcomponents in the type definition.
43+ // Letting this be implicit works in this project but fails in projects that use
44+ // generated *.d.ts files.
45+
46+ export const Autocomplete : React . FunctionComponent < AutocompleteProps > & {
47+ ComboBox : typeof ComboBox ;
48+ TextField : typeof TextField ;
49+ } = function Autocomplete ( {
4250 id,
4351 options,
4452 selected,
@@ -86,7 +94,7 @@ export function Autocomplete({
8694 emptyState = { emptyState }
8795 />
8896 ) ;
89- }
97+ } ;
9098
91- Autocomplete . TextField = TextField ;
9299Autocomplete . ComboBox = ComboBox ;
100+ Autocomplete . TextField = TextField ;
Original file line number Diff line number Diff line change @@ -31,7 +31,16 @@ export interface CardProps {
3131 secondaryFooterActionsDisclosureText ?: string ;
3232}
3333
34- export function Card ( {
34+ // TypeScript can't generate types that correctly infer the typing of
35+ // subcomponents so explicitly state the subcomponents in the type definition.
36+ // Letting this be implicit works in this project but fails in projects that use
37+ // generated *.d.ts files.
38+
39+ export const Card : React . FunctionComponent < CardProps > & {
40+ Header : typeof Header ;
41+ Section : typeof Section ;
42+ Subsection : typeof Subsection ;
43+ } = function Card ( {
3544 children,
3645 title,
3746 subdued,
@@ -102,8 +111,8 @@ export function Card({
102111 </ div >
103112 </ WithinContentContext . Provider >
104113 ) ;
105- }
114+ } ;
106115
107- Card . Section = Section ;
108116Card . Header = Header ;
117+ Card . Section = Section ;
109118Card . Subsection = Subsection ;
Original file line number Diff line number Diff line change @@ -33,7 +33,16 @@ export interface TopBarProps {
3333 onNavigationToggle ?( ) : void ;
3434}
3535
36- export function TopBar ( {
36+ // TypeScript can't generate types that correctly infer the typing of
37+ // subcomponents so explicitly state the subcomponents in the type definition.
38+ // Letting this be implicit works in this project but fails in projects that use
39+ // generated *.d.ts files.
40+
41+ export const TopBar : React . FunctionComponent < TopBarProps > & {
42+ Menu : typeof Menu ;
43+ SearchField : typeof SearchField ;
44+ UserMenu : typeof UserMenu ;
45+ } = function TopBar ( {
3746 showNavigationToggle,
3847 userMenu,
3948 searchResults,
@@ -123,8 +132,8 @@ export function TopBar({
123132 </ div >
124133 </ div >
125134 ) ;
126- }
135+ } ;
127136
128- TopBar . UserMenu = UserMenu ;
129- TopBar . SearchField = SearchField ;
130137TopBar . Menu = Menu ;
138+ TopBar . SearchField = SearchField ;
139+ TopBar . UserMenu = UserMenu ;
You can’t perform that action at this time.
0 commit comments