Skip to content

Commit e051cc8

Browse files
committed
Workaround for several issues I reported in #100. ElementType fix is adjusted from latest React definitions. I also had to do one change in Custom events property in EventHandler<T> declaration as TypeScript complains about index string compatibility.
1 parent 17b9cdf commit e051cc8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

types/index.d.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export function ShadowRoot(
214214
}
215215

216216
export interface FunctionComponent<P = {}, T extends Element = JSX.Element> {
217-
(props: P, context?: any): T | null
217+
(props: PropsWithChildren<P>, context?: any): T | null
218218
defaultProps?: Partial<P>
219219
displayName?: string
220220
}
@@ -235,7 +235,7 @@ export class Component<P = {}, T extends Element = JSX.Element> {
235235

236236
export { Component as PureComponent }
237237

238-
export type PropsWithChildren<P = unknown> = P & { children?: ReactNode | undefined }
238+
export type PropsWithChildren<P> = P & { children?: ReactNode | undefined }
239239

240240
export type ComponentType<P = {}, T extends Element = JSX.Element> =
241241
| ComponentClass<P, T>
@@ -489,7 +489,7 @@ interface EventHandlers<T> {
489489
transitionend?: TransitionEventHandler<T> | undefined
490490

491491
// Custom events
492-
[K: string]: ReactEventHandler<T> | undefined
492+
[K: string]: EventHandler<any, T> | undefined
493493
}
494494

495495
export interface DOMAttributes<T> {
@@ -2046,6 +2046,14 @@ interface ReactSVG {
20462046
view: SVGFactory
20472047
}
20482048

2049+
type JSXElementConstructor<P> =
2050+
| ((
2051+
props: P
2052+
) => ReactNode)
2053+
| (new(
2054+
props: P
2055+
) => Component<any, any>);
2056+
20492057
export namespace JSX {
20502058
// We don't just alias React.ElementType because React.ElementType
20512059
// historically does more than we need it to.
@@ -2058,8 +2066,7 @@ export namespace JSX {
20582066
// .propTypes assignability so we might as well drop it entirely here to
20592067
// reduce the work of the type-checker.
20602068
// TODO: Check impact of making React.ElementType<P = any> = React.JSXElementConstructor<P>
2061-
type ElementType = string
2062-
2069+
type ElementType = string | JSXElementConstructor<any>;
20632070
type Element = ReactElement
20642071

20652072
interface ElementAttributesProperty {

0 commit comments

Comments
 (0)