Repository: remix-run/react-router
File: integration/typegen-test.ts (TypeScript)

Code before:
      const cwd = await createProject({
        "vite.config.ts": viteConfig,
        "app/expect-type.ts": expectType,
        "app/routes.ts": tsx`
          import { type RouteConfig, route } from "@react-router/dev/routes";

          export default [
            route("only-required/:id/:id", "routes/only-required.tsx"),
            route("only-optional/:id?/:id?", "routes/only-optional.tsx"),
            route("optional-then-required/:id?/:id", "routes/optional-then-required.tsx"),
            route("required-then-optional/:id/:id?", "routes/required-then-optional.tsx"),
          ] satisfies RouteConfig;
        `,
        "app/routes/only-required.tsx": tsx`
          import type { Expect, Equal } from "../expect-type"
          import type { Route } from "./+types/only-required"
          export function loader({ params }: Route.LoaderArgs) {
            type Test = Expect<Equal<typeof params, { id: string }>>
            return null
          }
        `,
        "app/routes/only-optional.tsx": tsx`
          import type { Expect, Equal } from "../expect-type"
          import type { Route } from "./+types/only-optional"
          export function loader({ params }: Route.LoaderArgs) {
            type Test = Expect<Equal<typeof params.id, string | undefined>>
            return null
          }
        `,
        "app/routes/optional-then-required.tsx": tsx`
          import type { Expect, Equal } from "../expect-type"
          import type { Route } from "./+types/optional-then-required"
          export function loader({ params }: Route.LoaderArgs) {
            type Test = Expect<Equal<typeof params.id,  string>>
            return null
          }
        `,
        "app/routes/required-then-optional.tsx": tsx`
          import type { Expect, Equal } from "../expect-type"
          import type { Route } from "./+types/required-then-optional"

          export function loader({ params }: Route.LoaderArgs) {
            type Test = Expect<Equal<typeof params.id, string>>
            return null
          }
        `,
      });
      console.log({ cwd });
      const proc = typecheck(cwd);
      expect(proc.stdout.toString()).toBe("");
      expect(proc.stderr.toString()).toBe("");

Review comment (refactor):
Expanding optionals means that `params` become a union, so can't just check a single object. Can we simplify this at all?

```ts
type x1 = { id?: undefined } | { id: string } | { id: string }
type x2 = { id: string } | { id: string }
```

Code after:
      const cwd = await createProject({
        "vite.config.ts": viteConfig,
        "app/expect-type.ts": expectType,
        "app/routes.ts": tsx`
          import { type RouteConfig, route } from "@react-router/dev/routes";

          export default [
            route("only-required/:id/:id", "routes/only-required.tsx"),
            route("only-optional/:id?/:id?", "routes/only-optional.tsx"),
            route("optional-then-required/:id?/:id", "routes/optional-then-required.tsx"),
            route("required-then-optional/:id/:id?", "routes/required-then-optional.tsx"),
          ] satisfies RouteConfig;
        `,
        "app/routes/only-required.tsx": tsx`
          import type { Expect, Equal } from "../expect-type"
          import type { Route } from "./+types/only-required"
          export function loader({ params }: Route.LoaderArgs) {
            type Test = Expect<Equal<typeof params, { id: string }>>
            return null
          }
        `,
        "app/routes/only-optional.tsx": tsx`
          import type { Expect, Equal } from "../expect-type"
          import type { Route } from "./+types/only-optional"
          export function loader({ params }: Route.LoaderArgs) {
            type Test = Expect<Equal<typeof params.id, string | undefined>>
            return null
          }
        `,
        "app/routes/optional-then-required.tsx": tsx`
          import type { Expect, Equal } from "../expect-type"
          import type { Route } from "./+types/optional-then-required"
          export function loader({ params }: Route.LoaderArgs) {
            type Test = Expect<Equal<typeof params.id,  string>>
            return null
          }
        `,
        "app/routes/required-then-optional.tsx": tsx`
          import type { Expect, Equal } from "../expect-type"
          import type { Route } from "./+types/required-then-optional"

          export function loader({ params }: Route.LoaderArgs) {
            type Test = Expect<Equal<typeof params.id, string>>
            return null
          }
        `,
      });
      const proc = typecheck(cwd);
      expect(proc.stdout.toString()).toBe("");
      expect(proc.stderr.toString()).toBe("");
      expect(proc.status).toBe(0);