Skip to content

Commit 6eaaed8

Browse files
authored
fix: Update typings to allow any react component (#395)
* Update typings to allow any react component * Remove unnecessary typings
1 parent 90e04a7 commit 6eaaed8

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

typings/carouselElements.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react'
1+
import React from 'react'
22

33
interface SliderProps extends React.HTMLAttributes<HTMLDivElement> {
44
readonly children: React.ReactNode
@@ -13,7 +13,7 @@ interface SliderProps extends React.HTMLAttributes<HTMLDivElement> {
1313
readonly trayTag?: string
1414
readonly trayProps?: React.HTMLAttributes<HTMLUListElement>
1515
}
16-
type SliderInterface = React.ComponentClass<SliderProps>
16+
type SliderInterface = React.ComponentType<SliderProps>
1717
/**
1818
* A Slider is a viewport that masks slides. The Slider component must wrap one or more Slide components.
1919
*/
@@ -34,7 +34,7 @@ interface SlideProps extends React.HTMLAttributes<HTMLDivElement> {
3434
readonly tag?: string
3535
readonly style?: {}
3636
}
37-
type SlideInterface = React.ComponentClass<SlideProps>
37+
type SlideInterface = React.ComponentType<SlideProps>
3838
/**
3939
* The Slide component is a container with an intrinsic ratio computed by the
4040
* CarouselProvider naturalSlideWidth and naturalSlideHeight properties.
@@ -59,7 +59,7 @@ interface ImageWithZoomProps {
5959
readonly tag?: string
6060
readonly isPinchZoomEnabled?: boolean
6161
}
62-
type ImageWithZoomInterface = React.ComponentClass<ImageWithZoomProps>
62+
type ImageWithZoomInterface = React.ComponentType<ImageWithZoomProps>
6363
declare const ImageWithZoom: ImageWithZoomInterface
6464

6565

typings/index.d.ts

+17-23
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Definitions by: Jedrzej Lewandowski <https://github.com/TheFullResolution>
33
// TypeScript Version: 2.7.2
44

5-
import * as React from 'react'
5+
import React from 'react'
66
import {
77
ButtonBack,
88
ButtonFirst,
@@ -26,7 +26,7 @@ import {
2626
ButtonLastProps,
2727
ButtonFirstProps,
2828
ButtonPlayProps
29-
} from './carouselElements.d'
29+
} from './carouselElements'
3030

3131
interface CarouselState {
3232
readonly currentSlide: number
@@ -97,7 +97,7 @@ interface CarouselProviderProps {
9797
readonly isIntrinsicHeight?: CarouselState['isIntrinsicHeight']
9898
}
9999

100-
type CarouselProviderInterface = React.ComponentClass<CarouselProviderProps>
100+
type CarouselProviderInterface = React.ComponentType<CarouselProviderProps>
101101
/**
102102
* CarouselProvider allows the other carousel components to communicate with each other.
103103
*
@@ -115,31 +115,25 @@ type CarouselProviderInterface = React.ComponentClass<CarouselProviderProps>
115115
declare const CarouselProvider: CarouselProviderInterface
116116

117117
export interface CarouselInjectedProps {
118-
readonly carouselStore: CarouselStoreInterface
118+
readonly carouselStore: Pick<
119+
CarouselStoreInterface,
120+
| "getStoreState"
121+
| "masterSpinnerError"
122+
| "masterSpinnerSuccess"
123+
| "setStoreState"
124+
| "subscribeMasterSpinner"
125+
| "unsubscribeAllMasterSpinner"
126+
| "unsubscribeMasterSpinner"
127+
>;
119128
}
120129

121-
// Diff / Omit taken from https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-311923766
122-
type Diff<T extends string, U extends string> = ({ [P in T]: P } &
123-
{ [P in U]: never } & { readonly [x: string]: never })[T]
124-
type Omit<T, K extends keyof T> = Pick<T, Diff<Extract<keyof T, string>, Extract<K, string>>>
125-
126130
type MapStateToProps<TStateProps> = (state: CarouselState) => TStateProps
127131

128132
interface WithStoreInterface {
129-
<CustomProps extends CarouselInjectedProps>(
130-
component: React.ComponentClass<CustomProps>
131-
): React.ComponentClass<Omit<CustomProps, keyof CarouselInjectedProps>> & {
132-
readonly WrappedComponent: React.ComponentClass<CustomProps>
133-
}
134-
135-
<CustomProps extends CarouselInjectedProps, CustomStateProps>(
136-
component: React.ComponentClass<CustomProps & CustomStateProps>,
137-
state: MapStateToProps<CustomStateProps>
138-
): React.ComponentClass<Omit<CustomProps, keyof CarouselInjectedProps>> & {
139-
readonly WrappedComponent: React.ComponentClass<
140-
CustomProps & CustomStateProps
141-
>
142-
}
133+
<CustomProps, CustomStateProps = {}>(
134+
component: React.ComponentType<CustomProps & CustomStateProps & CarouselInjectedProps>,
135+
mapStateToProps?: MapStateToProps<CustomStateProps>
136+
): React.ComponentType<CustomProps>
143137
}
144138
/**
145139
* Use this HOC to pass CarouselProvider state properties as props to a component.

0 commit comments

Comments
 (0)