Skip to content

Fix renderUsername type for strictFunctionTypes compatibility#2726

Open
dannyDotDev wants to merge 1 commit intoFaridSafi:masterfrom
dannyDotDev:fix/render-username-strict-types
Open

Fix renderUsername type for strictFunctionTypes compatibility#2726
dannyDotDev wants to merge 1 commit intoFaridSafi:masterfrom
dannyDotDev:fix/render-username-strict-types

Conversation

@dannyDotDev
Copy link
Copy Markdown

Summary

  • Fix TypeScript error when strictFunctionTypes is enabled (e.g. Expo's default tsconfig)
  • renderUsername prop in BubbleProps is typed as (user?: TMessage['user']) => ReactNode, but gets passed to renderComponentOrElement which expects (props: TProps) => ReactNode where TProps extends Record<string, any>
  • With strict function types, the optional parameter creates a contravariance mismatch

The Error

error TS2345: Argument of type '(user?: TMessage["user"] | undefined) => ReactNode'
is not assignable to parameter of type '... | ((props: Record<string, any>) => ReactNode) | ...'

At src/Bubble/index.tsx:296:

return renderComponentOrElement(renderUsername, currentMessage.user)

Fix

One-line change in src/Bubble/types.ts:

- renderUsername?: (user?: TMessage['user']) => React.ReactNode
+ renderUsername?: (props: TMessage['user']) => React.ReactNode

The parameter was already always called with currentMessage.user (never undefined), so making it required matches actual usage. This is similar to the fixes in #2698.

Test

  • Verified typecheck passes with strictFunctionTypes: true and strictNullChecks: true
  • No runtime behavior change — just a type signature correction

The renderUsername prop was typed as (user?: TMessage['user']) => ReactNode
but gets passed to renderComponentOrElement which expects
(props: TProps) => ReactNode where TProps extends Record<string, any>.

With strictFunctionTypes enabled (e.g. Expo's default tsconfig), the
optional parameter creates a contravariance mismatch. The parameter is
always called with currentMessage.user (never undefined), so making it
required matches actual usage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant