Skip to content

Commit

Permalink
upgrade typings to work with latest ts (#428)
Browse files Browse the repository at this point in the history
* upgrade typings to work with latest ts

* fix form component
  • Loading branch information
nathanmarks authored Jul 28, 2020
1 parent 4a954ce commit c100c21
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@instacart/tsconfig": "0.1.1",
"@svgr/cli": "4.3.0",
"@svgr/webpack": "4.3.0",
"@types/node": "14.0.26",
"@types/react": "16.9.35",
"babel-jest": "^24.8.0",
"babel-loader": "^8.0.0",
Expand Down
8 changes: 4 additions & 4 deletions src/components/Forms/FormComponent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ type FormComponentRef<T extends React.ComponentType<any>> = {

declare function formComponent<
T extends React.ComponentType<P>,
P extends FormComponentInjectedProps = React.ComponentProps<T>
P extends FormComponentInjectedProps
>(
component: T
): React.ComponentType<WithoutInjectedProps<React.PropsWithoutRef<P>> & FormComponentOuterProps<T>>
component: T & React.ComponentType<P>
): React.ComponentType<WithoutInjectedProps<P> & FormComponentOuterProps<T>>

// helper for applying hoc in .d.ts files
export type ApplyFormComponent<
T extends React.ComponentType<P>,
P extends FormComponentInjectedProps = React.ComponentProps<T>
> = React.ComponentType<WithoutInjectedProps<React.PropsWithoutRef<P>> & FormComponentOuterProps<T>>
> = React.ComponentType<WithoutInjectedProps<P> & FormComponentOuterProps<T>>

export default formComponent
10 changes: 5 additions & 5 deletions src/styles/themer/withTheme.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type WithThemeOuterProps<P extends WithThemeInjectedProps> = Omit<P, keyof WithT
export type ApplyWithTheme<
T extends React.ComponentType<P>,
P extends WithThemeInjectedProps = React.ComponentProps<T>
> = React.ComponentClass<WithThemeOuterProps<React.PropsWithoutRef<P>>>
> = React.ComponentClass<WithThemeOuterProps<P>>

export type ApplyWithThemeForwardRef<
T extends React.ComponentType<P>,
Expand All @@ -31,13 +31,13 @@ export interface WithThemeOptions {

declare function withTheme<TOptions extends WithThemeOptions>(
options?: TOptions
): <T extends React.ComponentType<P>, P extends WithThemeInjectedProps = React.ComponentProps<T>>(
component: T
): <T extends React.ComponentType<P>, P extends WithThemeInjectedProps>(
component: T & React.ComponentType<P>
) => TOptions extends { forwardRef: true }
? React.NamedExoticComponent<JSX.LibraryManagedAttributes<T, WithThemeOuterProps<P>>>
: React.ComponentClass<WithThemeOuterProps<React.PropsWithoutRef<P>>>
: React.ComponentClass<WithThemeOuterProps<P>>
declare function withTheme<
T extends React.ComponentType<P>,
P extends WithThemeInjectedProps = React.ComponentProps<T>
>(component: T): React.ComponentClass<WithThemeOuterProps<React.PropsWithoutRef<P>>>
>(component: T): React.ComponentClass<WithThemeOuterProps<P>>
export default withTheme
3 changes: 1 addition & 2 deletions test/typescript/FormInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react'
import { useImperativeHandle } from 'react'

import { withTheme, FormComponent } from '../../src'
import { WithThemeInjectedProps } from '../../src/styles/themer/withTheme'
Expand All @@ -14,7 +13,7 @@ interface FormInputProps extends WithThemeInjectedProps, FormComponentInjectedPr
const FormInput = React.forwardRef<FormInputRefApi, FormInputProps>((_, ref) => {
const inputRef = React.useRef<HTMLInputElement>(null)

useImperativeHandle(ref, () => ({
React.useImperativeHandle(ref, () => ({
focus: () => {
inputRef.current && inputRef.current.focus()
},
Expand Down
11 changes: 8 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,11 @@
version "9.4.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.6.tgz#d8176d864ee48753d053783e4e463aec86b8d82e"

"@types/[email protected]":
version "14.0.26"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.0.26.tgz#22a3b8a46510da8944b67bfc27df02c34a35331c"
integrity sha512-W+fpe5s91FBGE0pEa0lnqGLL4USgpLgs4nokw16SrBBco/gQxuua7KnArSEOd5iaMqbbSHV10vUDkJYJJqpXKA==

"@types/prop-types@*":
version "15.7.0"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.0.tgz#4c48fed958d6dcf9487195a0ef6456d5f6e0163a"
Expand Down Expand Up @@ -10824,9 +10829,9 @@ typedarray@^0.0.6:
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^3.2.2:
version "3.4.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.3.tgz#0eb320e4ace9b10eadf5bc6103286b0f8b7c224f"
integrity sha512-FFgHdPt4T/duxx6Ndf7hwgMZZjZpB+U0nMNGVCYPq0rEzWKjEDobm4J6yb3CS7naZ0yURFqdw9Gwc7UOh/P9oQ==
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

ua-parser-js@^0.7.9:
version "0.7.14"
Expand Down

0 comments on commit c100c21

Please sign in to comment.