Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript error when using a signal inside a React Native <Text> component #260

Open
elliotwaite opened this issue Nov 2, 2022 · 4 comments

Comments

@elliotwaite
Copy link
Contributor

When I try to use a signal as a child of a React Native <Text> component, it works, but I get the following TypeScript errors. Is there a way to make TypeScript allow the use of signals inside <Text> components?

This is the error when <Text> contains only a signal:

const count = signal(0)

export function Component() {
  return <Text>{count}</Text>
               ^^^^^^^
    TS2769: No overload matches this call.
      Overload 1 of 2, '(props: TextProps | Readonly<TextProps>): Text', gave the following error.
        Type 'Signal<number>' is not assignable to type 'ReactNode'.
      Overload 2 of 2, '(props: TextProps, context: any): Text', gave the following error.
        Type 'Signal<number>' is not assignable to type 'ReactNode'.

}

This is the error when <Text> contains both text and a signal:

const count = signal(0)

export function Component() {
  return <Text>Count: {count}</Text>
          ^^^^
    TS2746: This JSX tag's 'children' prop expects a single child of type 'ReactNode', but multiple children were provided.
    -----------------------------------------------------------------------------------------------------------------------
    TS2769: No overload matches this call.
      This JSX tag's 'children' prop expects a single child of type 'ReactNode', but multiple children were provided.
      This JSX tag's 'children' prop expects a single child of type 'ReactNode', but multiple children were provided.

}
@Cybermage83
Copy link

Confirming the issue, got the same

@ShivamJoker
Copy link

any updates on this?

@Voznov
Copy link

Voznov commented May 1, 2023

I solved it patching react-native typings

diff --git a/node_modules/react-native/Libraries/Text/Text.d.ts b/node_modules/react-native/Libraries/Text/Text.d.ts
index a9d2a1b..8274e84 100644
--- a/node_modules/react-native/Libraries/Text/Text.d.ts
+++ b/node_modules/react-native/Libraries/Text/Text.d.ts
@@ -19,6 +19,7 @@ import {
   NativeSyntheticEvent,
   TextLayoutEventData,
 } from '../Types/CoreEventTypes';
+import { Signal } from '@preact/signals-react';
 
 export interface TextPropsIOS {
   /**
@@ -107,7 +108,7 @@ export interface TextProps
    */
   allowFontScaling?: boolean | undefined;
 
-  children?: React.ReactNode;
+  children?: React.ReactNode | Signal<React.ReactNode>;
 
   /**
    * This can be one of the following values:

@geyang
Copy link

geyang commented Jul 24, 2024

running into similar issue with react in the web.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants