StaticRoutes type definition not exported from router.d.ts file
Beadle85 opened this issue · comments
Which package manager are you using? (Yarn is recommended)
npm
Summary
Hey there,
I think it would be helpful if the StaticRoutes type definition was exported from the router.d.ts file so we can have autocomplete for custom functions that need to only accept a StaticRoute path.
My apologies is this isn't the right place to share this.
Minimal reproducible example
`declare module "expo-router" {
import type { LinkProps as OriginalLinkProps } from 'expo-router/build/link/Link';
import type { Router as OriginalRouter } from 'expo-router/src/types';
export * from 'expo-router/build';
// prettier-ignore
add export here type StaticRoutes = /
| /login
// prettier-ignore
type DynamicRoutes = never;`
I solved it like so:
import { Href, Link } from "expo-router";
import React from "react";
interface HeaderLeft<T> extends HeaderButtonProps {
href: Href<T>;
}
export const HeaderLeft = <T,>(props: HeaderLeft<T>) => {
return (
<Link href={props.href}>
<HomeIcon size={32} />
</Link>
);
};```
And you still get autocomplete
@michalstruck , nicely done. That'll work for me. Thanks for your help!
Please add this example to the Typed Routes page on expo docs!
Spent way to long searching for this answer
I solved it like so:
import { Href, Link } from "expo-router"; import React from "react"; interface HeaderLeft<T> extends HeaderButtonProps { href: Href<T>; } export const HeaderLeft = <T,>(props: HeaderLeft<T>) => { return ( <Link href={props.href}> <HomeIcon size={32} /> </Link> ); };``` And you still get autocomplete
I feel like this is too much, isn't it? just a simple Href<string>
does for me.