No type error when using wrong path
MarchewkaMatthew opened this issue · comments
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
- Run
npx create-expo-app@latest --template tabs@sdk-49
- Run
npm start
to generate/.expo/types/router.d.ts
file - Go to
/app/(tabs)/_layout.tsx
and change the link href to/anything
- No typescript error about using the wrong path
![image](https://private-user-images.githubusercontent.com/56259093/255988639-ba54388f-d441-42eb-b358-96f6bb93311c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg3MDg0NTMsIm5iZiI6MTcxODcwODE1MywicGF0aCI6Ii81NjI1OTA5My8yNTU5ODg2MzktYmE1NDM4OGYtZDQ0MS00MmViLWIzNTgtOTZmNmJiOTMzMTFjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE4VDEwNTU1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNjNTJiNzA5ODk5YjliMjRmNzdkOTYwZGI3OTJmYTE2YTBmYjkxNTQ1ZDE5ZDRhNWEzMDMwYjhmZDAzZWFhY2EmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.8AZjltP3n813VEnaMuyaI8yUVxiBytGMuqBMcUFBMvo)
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.