Skip to content

Commit

Permalink
Fix TypeScript support for custom components with non-standard declar…
Browse files Browse the repository at this point in the history
…ations (#2181)

* Fix RMWC event handlers

* Add changeset

* Add RMWC-like component test

* Force TS version

* Update .changeset/silent-otters-build.md

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
  • Loading branch information
101arrowz and Andarist committed Dec 22, 2020
1 parent 7a328d6 commit 71ca9be
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-otters-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/react': patch
---

Fixed some typing issues with React components with custom generic render functions.
2 changes: 1 addition & 1 deletion packages/react/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
// TypeScript Version: 3.2
// TypeScript Version: 3.4

import { EmotionCache } from '@emotion/cache'
import {
Expand Down
6 changes: 3 additions & 3 deletions packages/react/types/jsx-namespace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Theme } from './index'

type WithConditionalCSSProp<P> = 'className' extends keyof P
? string extends P['className' & keyof P]
? P & { css?: Interpolation<Theme> }
: P
: P
? { css?: Interpolation<Theme> }
: {}
: {}

// unpack all here to avoid infinite self-referencing when defining our own JSX namespace
type ReactJSXElement = JSX.Element
Expand Down
16 changes: 16 additions & 0 deletions packages/react/types/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,19 @@ const anim1 = keyframes`
? true
: false
}

// RMWC-like component test
declare const OtherComponent: {
<Tag extends React.ElementType>(
props:
| React.AllHTMLAttributes<HTMLInputElement>
| React.ComponentPropsWithRef<Tag>,
ref: any
): JSX.Element
displayName?: string
}
;<OtherComponent
onChange={ev => {
console.log(ev.currentTarget.value)
}}
/>

0 comments on commit 71ca9be

Please sign in to comment.