question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript errors related to new component API?

See original GitHub issue

Hi. Fantastic library! Came across it thanks to a comment you made on the RNN repo.

I’m receiving the following ts errors with the Hello World example from the doc site:

(alias) class NavigationHandler
import NavigationHandler
Provides the navigation event data

No overload matches this call.
  Overload 1 of 2, '(props: { stateNavigator: StateNavigator<any, string>; } | Readonly<{ stateNavigator: StateNavigator<any, string>; }>): NavigationHandler', gave the following error.
    Type '{ children: Element; stateNavigator: StateNavigator<{ hello: any; } & { world: any; }, "hello" | "world">; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<NavigationHandler> & Readonly<{ stateNavigator: StateNavigator<any, string>; }>'.
      Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<NavigationHandler> & Readonly<{ stateNavigator: StateNavigator<any, string>; }>'.
  Overload 2 of 2, '(props: { stateNavigator: StateNavigator<any, string>; }, context: any): NavigationHandler', gave the following error.
    Type '{ children: Element; stateNavigator: StateNavigator<{ hello: any; } & { world: any; }, "hello" | "world">; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<NavigationHandler> & Readonly<{ stateNavigator: StateNavigator<any, string>; }>'.
      Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<NavigationHandler> & Readonly<{ stateNavigator: StateNavigator<any, string>; }>'.ts(2769)
(alias) class NavigationStack
import NavigationStack
Renders a stack of Scenes

No overload matches this call.
  Overload 1 of 2, '(props: NavigationStackProps | Readonly<NavigationStackProps>): NavigationStack', gave the following error.
    Type '{ children: Element[]; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<NavigationStack> & Readonly<NavigationStackProps>'.
  Overload 2 of 2, '(props: NavigationStackProps, context: any): NavigationStack', gave the following error.
    Type '{ children: Element[]; }' has no properties in common with type 'IntrinsicAttributes & IntrinsicClassAttributes<NavigationStack> & Readonly<NavigationStackProps>'.ts(2769)
(alias) class Scene<NavigationInfo extends { [index: string]: any; } = any>
import Scene
Configures the Scene for a State

No overload matches this call.
  Overload 1 of 2, '(props: SceneProps<{ hello: any; }> | Readonly<SceneProps<{ hello: any; }>>): Scene<{ hello: any; }>', gave the following error.
    Type '{ children: Element; stateKey: "hello"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Scene<{ hello: any; }>> & Readonly<SceneProps<{ hello: any; }>>'.
      Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Scene<{ hello: any; }>> & Readonly<SceneProps<{ hello: any; }>>'.
  Overload 2 of 2, '(props: SceneProps<{ hello: any; }>, context: any): Scene<{ hello: any; }>', gave the following error.
    Type '{ children: Element; stateKey: "hello"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Scene<{ hello: any; }>> & Readonly<SceneProps<{ hello: any; }>>'.
      Property 'children' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Scene<{ hello: any; }>> & Readonly<SceneProps<{ hello: any; }>>'.ts(2769)

Here’s the code for completeness:

import React from 'react'
import { Text, SafeAreaView } from 'react-native'
import { StateNavigator } from 'navigation'
import { NavigationHandler } from 'navigation-react'
import { NavigationStack, Scene } from 'navigation-react-native'

const stateNavigator = new StateNavigator([
  { key: 'hello' },
  { key: 'world', trackCrumbTrail: true },
])

const Hello = () => {
  return (
    <SafeAreaView>
      <Text>Hello</Text>
    </SafeAreaView>
  )
}

const World = () => {
  return (
    <SafeAreaView>
      <Text>World</Text>
    </SafeAreaView>
  )
}

export const App = () => (
  <NavigationHandler stateNavigator={stateNavigator}>
    <NavigationStack>
      <Scene stateKey="hello">
        <Hello />
      </Scene>
      <Scene stateKey="world">
        <World />
      </Scene>
    </NavigationStack>
  </NavigationHandler>
)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
grahammendickcommented, Jun 19, 2022

Hey there, I’m glad you like the Navigation router! Thanks for letting me know how you came across it.

I think that’s happening because the React 18 types dropped the implicit children prop. Now, components that accept children have to explicitly say so in their props type. Looks like there is a codemod that fixes it in the short term.

Would you be interested in making a PR that fixes it properly?

0reactions
grahammendickcommented, Jun 25, 2022

Just fixed this in ‘navigation-react v4.5.1’ and ‘navigation-react-native v8.9.1’. Thanks for raising it

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript errors and how to fix them
Common Errors. Below you find a list of common TypeScript errors along with the buggy code and its fixed version. If you're interested...
Read more >
Improving TypeScript error handling with exhaustive type ...
Discover an improved method for handling errors in TypeScript that solves problems that arise from returning null and throwing try...catch.
Read more >
API call is throwing error when converting to TypeScript
API call is throwing error when converting to TypeScript · That sort of error usually means that the function isn't expecting an async...
Read more >
Handling Errors in TypeScript - C# Corner
In this article, we will see the various errors that occurred while requesting from the client to the server. Also, we will create...
Read more >
TSConfig Reference - Docs on every TSConfig option
Future versions of TypeScript may introduce additional stricter checking under this flag, so upgrades of TypeScript might result in new type errors in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found