Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#553: Resolve type error due to wrong default prop of Carousel component #554

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class Carousel extends React.Component<Props, State> {

static displayName = 'Carousel';

static defaultProps = {
static defaultProps: Props = {
axis: 'horizontal',
centerSlidePercentage: 80,
interval: 3000,
Expand All @@ -100,7 +100,7 @@ export default class Carousel extends React.Component<Props, State> {
onChange: noop,
onSwipeStart: () => {},
onSwipeEnd: () => {},
onSwipeMove: () => {},
onSwipeMove: () => false,
preventMovementUntilSwipeScrollTolerance: false,
renderArrowPrev: (onClickHandler: () => void, hasPrev: boolean, label: string) => (
<button type="button" aria-label={label} className={klass.ARROW_PREV(!hasPrev)} onClick={onClickHandler} />
Expand Down Expand Up @@ -131,14 +131,14 @@ export default class Carousel extends React.Component<Props, State> {
return item;
},
renderThumbs: (children: React.ReactChild[]) => {
const images = Children.map(children, (item) => {
let img: React.ReactNode = item;
const images = Children.map<React.ReactChild | undefined, React.ReactChild>(children, (item) => {
let img: React.ReactChild | undefined = item;

// if the item is not an image, try to find the first image in the item's children.
if ((item as React.ReactElement<{ children: React.ReactChild[] }>).type !== 'img') {
img = Children.toArray(
(item as React.ReactElement<{ children: React.ReactChild[] }>).props.children
).find((children) => (children as React.ReactElement).type === 'img');
img = (Children.toArray((item as React.ReactElement).props.children) as React.ReactChild[]).find(
(children) => (children as React.ReactElement).type === 'img'
);
}

if (!img) {
Expand Down