typescript error in navigating with parameters

Having trouble adding a param with TypeScript and encountering the following error:

Error: Argument of type '["Profile", { screen: Screen; }]' is not assignable to parameter of type '[screen: "Explore"] | [screen: "Explore", params: any]'.
  Type '["Profile", { screen: Screen; }]' is not assignable to type '[screen: "Explore", params: any]'.
    Type at position 0 in source is not compatible with type at position 0 in target.
      Type '"Profile"' is not assignable to type '"Explore"'.ts(2345)

Any suggestions on how to resolve this issue?

The error seems to be occurring at line : "navigation.navigate("Profile", { params });" within the Explore file.

Explore

import { useNavigation } from '@react-navigation/core';
import { NativeStackScreenProps } from '@react-navigation/native-stack';
import React from 'react';
import { StyleSheet, Text, View, Pressable, ScrollView } from 'react-native';
import { RootStackParams } from '../../App';
import Card from '../components/Card';

type PropNav = NativeStackScreenProps<RootStackParams, 'Explore'>;


const Explore = ({ navigation }: PropNav) => {
  console.log(navigation);
  const handleNavigate = (params: string) => {
    navigation.navigate('Profile', { params });
  };
  
  return (
    <View>
      <ScrollView>
        <Card name="Zum Profil" onPress={(params) => handleNavigate(params)} />
      </ScrollView>
    </View>
  )
};

export default Explore;

Card

import React from 'react';
import { StyleSheet, Text, View, Pressable } from 'react-native';

type Props = {
  name: string,
  onPress: (params: string) => void
}

const Card = ({ name, onPress }: Props) => {
  return (
    <View>
      <Pressable onPress={() => onPress('Sushi')}>
        <Text>{ name }</Text>
      </Pressable>
    </View>
  )
};

export default Card;

....................................................................................................................................................................................................

Answer №1

To ensure everything is set up correctly, be certain that you included Profile within the RootStackParams:

export type RootStackParams = {
 Profile: {
  screen: Screen;
 };
 Explore: undefined
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular is a powerful framework that enables the creation of dynamic user interfaces. One of its many

Looking to implement a Material table with expandable rows in Angular. table-tree.html <table mat-table [dataSource]="dataSource" multiTemplateDataRows class="mat-elevation-z8" > <ng-container matColumnDef="{{co ...

Using the React UseEffect Hook allows for value updates to occur within the hook itself, but not within the main

I am currently utilizing a font-picker-react package to display fonts using the Google Font API. Whenever a new font is chosen from the dropdown, my goal is to update a field value accordingly. While the 'value' updates correctly within the ...

What causes the difference in inference for unspecified generics between a simple function call and a null-coalescing operator in TypeScript?

What causes the different types of a and b in the given code snippet? function empty<T>() { return [] as T[] } const defEmpty = empty() function test1(abc: number[]|null) { const a = abc ?? defEmpty const b = abc ?? empty() } Upon testing on t ...

Guide to highlighting manually selected months in the monthpicker by utilizing the DoCheck function in Angular

I'm facing an issue and I could really use some assistance. The problem seems quite straightforward, but I've hit a roadblock. I have even created a stackblitz to showcase the problem, but let me explain it first. So, I've developed my own t ...

The Clerk middleware is causing delays in loading, leading to a 504 Error on NextJS / Vercel with the message 'FUNCTION_INVOCATION_TIMEOUT'

I'm currently working on a web page where I need to utilize Clerk for authentication and login. However, I've encountered an issue with the middleware taking too long to load, causing deployment problems for the app. Here is the code from middle ...

Ways to employ data binding for extracting a user-input value and performing multiplication operations with the enclosed {{ ...}} tags

My API response includes the price of a product, which is represented as {{price}} I have a system where I can add or reduce the number of products: <div class="number-input"> <h2>Price: {{price }}</h2> <button oncli ...

Steps for storing API information in localStorage:1. Retrieve the API data

My app is running sluggish due to the excessive API calls for information retrieval. To optimize performance, I want to create a unified object containing all the data that can be shared across pages and accessed from localStorage, thus enhancing the app ...

Exploring the implementation of query parameters in Nest.js

I am currently a freshman in the world of Nest.js. Below is an excerpt from my code: @Get('findByFilter/:params') async findByFilter(@Query() query): Promise<Article[]> { } I have utilized Postman to test this specific router. ht ...

Create a custom data type that consists of a specific set of keys from an object

Is there a way to create a type in TypeScript that includes only a subset of keys from an object? Consider the example object below: const something = { cannary: "yellow", coyote: "brown", fox: "red", roses: "white", tulipan: "purple", palmera: ...

Angular real-time data tracker

As a newcomer to Angular, I am facing some challenges trying to achieve real-time data updates in my app. My goal is to retrieve JSON data from an MSSQL server via a web server. I have successfully fetched data using the following code: export class AppC ...

Solve the issue of the __typename union

Imagine having the following union: export type IBookmarkItemFragment = | ({ __typename: "Story" } & { story: number; }) | ({ __typename: "Product" } & { product: number; }) | ({ __typename: "Project" } & { proj ...

Tips for retrieving the most recent number dynamically in a separate component without needing to refresh the page

Utilizing both the Helloworld and New components, we aim to store a value in localStorage using the former and display it using the latter. Despite attempts to retrieve this data via computed properties, the need for manual refreshing persists. To explore ...

What is the correct way to bring in a utility in my playwright test when I am working with TypeScript?

I am working on a basic project using playwright and typescript. My goal is to implement a logger.ts file that will manage log files and log any logger.info messages in those files. To set up my project, I used the following commands and created a playwri ...

Adjust the dimensions of an image to maintain a 16:9 aspect ratio

After spending the entire day trying to resize the uploaded image to a 16:9 aspect ratio, this is the closest I have come. const resizeResult = await manipulateAsync( uploadResult.uri, [ { resize: uploadResult.width > uploadResult. ...

Proper way to link another class in typegoose (mongoose) and store only the reference (ObjectId)?

When attempting to save certain fields in ObjectId only in the mongo db, I encountered an issue with the code below: @ObjectType() export class User { @prop() @Field() name: string; @prop({ ref: () => OtherClassA }) @Field() otherClassA: Ot ...

What is the best way to represent a state with two possible fields in React using TypeScript?

There is a specific state item that can have its own value or reference another item using an ID. interface Item { itemName: string; itemValue: { valLiteral: number } | { idNumber: string }; } const indItem1: Item = { itemName: "first sample&quo ...

What is the proper way to add a string to a TypeScript array?

When attempting to add a string to a TypeScript array, I am encountering an error stating 'cannot push to undefined'. Is this the correct approach, or should I be using the spread operator instead? api.ts const api: IConfigName = {name: "getKey ...

Enable lazy loading to retrieve the current routed module

I'm currently working on a way to exclude a component when a specific module is routed in a lazy loading application. For instance, in my AppComponent I have a router-outlet and a component above it: <div> <my-component></my-compo ...

Checking the types for object literals returned from Array.map functions

Check out this demonstration I made in the TypeScript playground: interface Test{ a: string b: string } const object: Test = { a: 'b', b: 'c', } function testIt(): Test[] { const data = [{b: '2', c: &apo ...

Limit file upload size to less than 1MB in Angular 2 with typescript using ng2-file-upload

Having issue with my code - I can't upload a file larger than 1mb even though maxFileSize is set to 50mb. Can anyone help me troubleshoot? @Component({ moduleId: module.id, selector: 'NeedAnalysisConsult', templateUrl: 'nee ...