Skip to content

Commit

Permalink
fix: force return type of Trans component
Browse files Browse the repository at this point in the history
Closes #801
  • Loading branch information
tricoder42 committed Nov 1, 2020
1 parent 59a412c commit ed3b124
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/react/src/Trans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ export type TransRenderProps = {
message?: string | null
}

export type TransRenderType =
| React.ComponentType<TransRenderProps>
| React.ElementType<TransRenderProps>

export type TransProps = {
id: string
message?: string
values: Object
components: { [key: string]: React.ElementType | any }
formats?: Object
component?: TransRenderType
render?: (opts: TransRenderProps) => TransRenderType
component?: React.ComponentType<TransRenderProps>
render?: (props: TransRenderProps) => React.ReactElement<any, any> | null
}

export function Trans(props: TransProps) {
export function Trans(props: TransProps): React.ReactElement<any, any> | null {
const { i18n, defaultComponent } = useLingui()
const { render, component, id, message, formats } = props

Expand Down Expand Up @@ -66,7 +62,9 @@ export function Trans(props: TransProps) {
: null

if (render === null || component === null) {
return translation
// Although `string` is a valid react element, types only allow `Element`
// Upstream issue: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
return (translation as unknown) as React.ReactElement<any, any>
}

const FallbackComponent = defaultComponent || React.Fragment
Expand Down

0 comments on commit ed3b124

Please sign in to comment.