remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
53.35k stars 10.34k forks source link

v7 - types not being exported by react-router #12431

Open kelvin2200 opened 2 days ago

kelvin2200 commented 2 days ago

I'm using React Router as a...

library

Reproduction

import { matchRoutes } from "react-router";

import { createBrowserHistory } from "history";

export const history = createBrowserHistory();

const routes = [];

/**
 * Bogus function
 * not used anywhere
 * needed to generate a type that we cannot import
 */
function makeInitialMatchesDummy(routes: any[]) {
    return matchRoutes(routes, history.location.pathname);
}

const initialMatches: NonNullable<ReturnType<typeof makeInitialMatchesDummy>> = [];

// exporting this type results in an error (does not happen with v6)
export type IniMatches = typeof initialMatches;

System Info

Windows 11, Vite, Yarn 4.5.3

Used Package Manager

yarn

Expected Behavior

I expect to be able to re-export any type that I can infer

Actual Behavior

react-router-7

NicoLaval commented 1 day ago

Same here, temporarily import "react-router/dist/production" instead of "react-router" to have types. But it breaks running...

brookslybrand commented 17 hours ago

@kelvin2200

I'm not able to reproduce this. I'm wondering if it's something specific to your tsconfig file. Can you please provide a reproduction on Stackblitz or something similar?