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.36k stars 113 forks source link

Href<T> breaks type checking on CI #746

Open robrechtme opened 1 year ago

robrechtme commented 1 year ago

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

yarn

Summary

👋 Not sure if this is a bug or a feature request...

We have a basic yarn tsc check runnning on CI for pull requests, which fails on TypeScript errors. If try to use the Href<T> type, the CI pipeline breaks, because these types are dynamically generated. Is there a way to generate these dynamic types on CI?

Minimal reproducible example

Simple example:

interface Props {
  to: Href<string>; 
   // ^ error TS2305: Module '"expo-router"' has no exported member 'Href'.
  title: string;
}

export const ListItem = ({ to, title }: Props) => { ... };
caioedut commented 1 year ago

Same here :(

jdziadek commented 1 year ago

Same

davecalnan commented 1 year ago

I've used a workaround of running pnpm start and killing it after 10 seconds using timeout. Here's an example working for me on GitHub actions:

- name: ʦ Generate mobile router types
  run: timeout 10 pnpm start
  working-directory: apps/mobile
  continue-on-error: true

This could be quite brittle but works for now. Replace pnpm start with yarn start or pnpm run start and change/remove working-directory as needed. continue-on-error: true is needed as timeout returns a non-zero exit code and fails the job otherwise. timeout is available on GitHub Linux runners, on macOS you can do brew install coreutils to get timeout.

robertherber commented 1 year ago

Also looking for a good solution for this.

My current workaround is to add .expo/types to git, modifying my .gitignore like this, feels like an okayish solution at this time:

.expo/*
!.expo/types/
oikalyptus commented 1 year ago

@robertherber ’s fix is a nice temporary solution.

la55u commented 9 months ago

It seems there is now a command to generate the types on demand. From the docs here:

If you find yourself in a situation where you need to generate these types without initiating the development server, such as during type checking on a Continuous Integration (CI) server. To do this, run the command npx expo customize tsconfig.json on the CI.

Which would solve OP's issue (and mine) but the command doesn't seem to work for me at least. I'm getting the following error:

CommandError: Invalid files: tsconfig.json. Allowed: babel.config.js, webpack.config.js, metro.config.js, web/serve.json, web/index.html

What am I doing wrong?

Related issue: https://github.com/expo/expo/issues/24818

johnjensenish commented 9 months ago

What am I doing wrong?

Related issue: expo/expo#24818

For folks following along, the related issue has now been fixed & now you can use npx expo customize tsconfig.json as of expo@49.0.16.

the-simian commented 4 months ago

@johnjensenish we can still repro this error in expo v50 even after running the npx expo customize tsconfig.json

  "expo": "~50.0.14",
  "expo-router": "3.4.8",
  "react-native": "0.73.6",   

@robertherber 's solution is still a viable workaround.

daxaxelrod commented 2 months ago

Getting this with expo router Href and Route types