expo / router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps
https://docs.expo.dev/routing/introduction/
1.37k stars 114 forks source link

No type error when using wrong path #808

Closed MarchewkaMatthew closed 1 year ago

MarchewkaMatthew commented 1 year ago

Which package manager are you using? (Yarn is recommended)

npm

Summary

Hi,

Thank you for maintaining this module. I have a question regarding the type-safety of the <Link /> component using expo-router v2 and expo SDK 49. I've created a new project using the npx create-expo-app@latest --template tabs@sdk-49 command. After the first run, I wanted to try typed hrefs, unfortunately, there is no TS error when I use the wrong path (type hints work well when I type, so TypeScript is able to read the /.expo/types/router.d.ts file). Is there any way to make it more secure and allow only registered routes?

Here are the related packages versions:

    "expo": "~49.0.5",
    "@react-navigation/native": "^6.0.2",
    "expo-router": "2.0.0",
    "typescript": "^5.1.3",

Minimal reproducible example

  1. Run npx create-expo-app@latest --template tabs@sdk-49
  2. Run npm start to generate /.expo/types/router.d.ts file
  3. Go to /app/(tabs)/_layout.tsx and change the link href to /anything
  4. No typescript error about using the wrong path
image
marklawlor commented 1 year ago

That example has a route [...missing].tsx which is a catch-all route on the top level - meaning all routes are "registered" from a types perspective.

This is an unfortunately side-effect while we are still exploring options to best represent 404 and/or error pages.