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

Commit

Permalink
fix review comment: fix handling of ShorthandCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed Jul 16, 2019
1 parent 0bd3449 commit 83c1577
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions build/gulp/plugins/util/parseType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { ComponentPropType } from 'docs/src/types'
import { PropItem } from './docgen'
import parseTypeAnnotation from './parseTypeAnnotation'

/** Performs transform: `ShorthandValue<T & { kind?: N }>` to `ShorthandCollection<T>[]`. */
/** Performs transform: `ShorthandValue<T & { kind?: N }>` to `ShorthandCollection<T, N>[]`. */
const normalizeShorthandCollection = (propType: string): string => {
const regex = /ShorthandValue<(.+) & { kind\?: .+; }>\[]$/
const regex = /ShorthandValue<(.+) & { kind\?: (.+); }>\[]$/
const result = regex.exec(propType)

if (result) {
return `ShorthandCollection<${result[1]}>`
return `ShorthandCollection<${result[1]}, ${result[2]}>`
}

return propType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ const ComponentPropValue: React.FunctionComponent<ComponentPropType> = props =>
if (name === 'literal') return <span>enum</span>
if (name === 'ShorthandValue' || name === 'ShorthandCollection') {
const componentName = parameters[0].name.replace('Props', '')
const kindIsDefined = name === 'ShorthandCollection' && parameters[1].name !== 'never'

return (
<span>
{name}
{`<`}
<Link to={`/components/${componentName}`}>{parameters[0].name}</Link>
{kindIsDefined && <span>, {parameters[1].name}</span>}
{`>`}
</span>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type ReactNode =
| undefined

export type ShorthandValue<P> = ReactNode | Props<P>
export type ShorthandCollection<P, K = []> = ShorthandValue<P & { kind?: K }>[]
export type ShorthandCollection<P, K = never> = ShorthandValue<P & { kind?: K }>[]

// ========================================================
// Types for As prop support
Expand Down

0 comments on commit 83c1577

Please sign in to comment.