Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

fix(factories): add types to createShorthandFactory() methods #1875

Merged
merged 10 commits into from
Sep 3, 2019

Conversation

lucivpav
Copy link
Contributor

@lucivpav lucivpav commented Sep 2, 2019

Fixes #1865

The new type is

export type ShorthandFactory = (
  value: ShorthandValue<UIComponentProps>,
  options?: CreateShorthandOptions,
) => React.ReactElement | null | undefined

Won't compile

{Avatar.create(Symbol("foo"), "FOO", "BAR")}
{Avatar.create(Symbol("foo"))}

Will compile

avatar?: ShorthandValue<AvatarProps> = ...
{Avatar.create(avatar}, {defaultProps: {...}, overrideProps: {...}}
{Avatar.create(avatar}}

And this will unfortunately also compile

button?: ShorthandValue<ButtonProps> = ...
{Avatar.create(button}}

@lucivpav lucivpav added 🚀 ready for review 🧰 fix Introduces fix for broken behavior. labels Sep 2, 2019
@@ -91,6 +92,10 @@ type CreateShorthandFactoryConfigInner<TPropName = string> = {
mappedArrayProp?: TPropName
}
export type CreateShorthandFactoryConfig = CreateShorthandFactoryConfigInner
export type CreateShorthandFactoryResult = (
a: ShorthandValue<UIComponentProps>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
a: ShorthandValue<UIComponentProps>,
value: ShorthandValue<UIComponentProps>,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
a: ShorthandValue<UIComponentProps>,
a: ShorthandValue<P>,

Actually, let's make it generic and accept component props there. Hope that it will work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works

@codecov
Copy link

codecov bot commented Sep 2, 2019

Codecov Report

Merging #1875 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1875   +/-   ##
======================================
  Coverage    69.7%   69.7%           
======================================
  Files         886     886           
  Lines        7797    7797           
  Branches     2258    2258           
======================================
  Hits         5435    5435           
  Misses       2352    2352           
  Partials       10      10
Impacted Files Coverage Δ
packages/react/src/components/Header/Header.tsx 100% <ø> (ø) ⬆️
packages/react/src/components/Label/Label.tsx 95.23% <ø> (ø) ⬆️
packages/react/src/components/Menu/MenuDivider.tsx 100% <ø> (ø) ⬆️
packages/react/src/components/List/ListItem.tsx 100% <ø> (ø) ⬆️
packages/react/src/components/Divider/Divider.tsx 100% <ø> (ø) ⬆️
packages/react/src/components/Video/Video.tsx 81.81% <ø> (ø) ⬆️
packages/react/src/components/Flex/FlexItem.tsx 78.57% <ø> (ø) ⬆️
packages/react/src/components/Popup/Popup.tsx 66.11% <ø> (ø) ⬆️
packages/react/src/components/Form/Form.tsx 100% <ø> (ø) ⬆️
...react/src/components/Toolbar/ToolbarCustomItem.tsx 100% <ø> (ø) ⬆️
... and 47 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c13a32...1066c4a. Read the comment docs.

…o "value, options", avoid cirtular reference in factories.ts
@vercel vercel bot temporarily deployed to staging September 2, 2019 13:58 Inactive
@@ -214,7 +215,8 @@ class MenuItem extends AutoControlledComponent<WithAsProp<MenuItemProps>, MenuIt
} = this.props
const { menuOpen } = this.state

const indicatorWithDefaults = indicator === undefined ? {} : indicator
const defaultIndicator = { name: vertical ? 'stardust-arrow-end' : 'stardust-arrow-down' }
const indicatorWithDefaults = indicator === undefined ? defaultIndicator : indicator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes required? Can we revert them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required, because Type {} is not assignable to type Props<IconProps>.

@@ -106,7 +107,8 @@ class AccordionTitle extends UIComponent<WithAsProp<AccordionTitleProps>, any> {

renderComponent({ ElementType, classes, unhandledProps, styles, accessibility }) {
const { contentRef, children, content, indicator, active } = this.props
const indicatorWithDefaults = indicator === undefined ? {} : indicator
const defaultIndicator = { name: active ? 'stardust-arrow-down' : 'stardust-arrow-end' }
const indicatorWithDefaults = indicator === undefined ? defaultIndicator : indicator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucivpav
Copy link
Contributor Author

lucivpav commented Sep 3, 2019

Another PR: CreateShorthandOptions should be typed as CreateShorthandOptions<P>

@vercel vercel bot temporarily deployed to staging September 3, 2019 11:01 Inactive
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🧰 fix Introduces fix for broken behavior. 🚀 ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typings: Factories are not properly typed
2 participants