-
Notifications
You must be signed in to change notification settings - Fork 113
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
How to type props of a route with Typescript? #103
Comments
Expo Router is based in react-navigation, which that means you can use react-navigation props to type your rote params. |
Would be good to get an example of usage of Eg. does this example below from the the link from @koka0012 translate 1-to-1 to usage in import type { NativeStackScreenProps } from '@react-navigation/native-stack';
type RootStackParamList = {
Home: undefined;
Profile: { userId: string };
Feed: { sort: 'latest' | 'top' } | undefined;
};
type Props = NativeStackScreenProps<RootStackParamList, 'Profile'>; For example, one difference that I could imagine would be that the keys would be lowercase in type RootStackParamList = {
home: undefined;
profile: { userId: string };
feed: { sort: 'latest' | 'top' } | undefined;
}; Maybe also in the cc @EvanBacon |
Yes please to exported type for route's! |
Having that, directly from |
My focus is primarily on getting things working consistently without errors, but I would love to have some fully automated type system in the future. Off the top, we probably need the following:
Further, it would be nice to have some automatic typing (far in the future as this is fragile and strenuous to maintain):
@marklawlor probably has some good ideas for this. |
Nice, thanks for the answer! Do your lists above also include the route parameters, which were the things that the original issue description and my comment above were referring to? |
Yeah I think one of the main things I needed was just a generic that would give me the props that each route has, I dont (right now) need type safe route params etc e.g. import { RouteProps } from "expo-router"
interface MyParams {
id: string
}
export default function MyRoute(props: RouteProps<MyParams>) {
const id = props.params.id // or whatever the actual route props object is
... |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Is there an exported type we can use to type the props?
In Next.js this is type like:
app/blog/[id].js
The text was updated successfully, but these errors were encountered: