Repository navigation
Conversation
cpojer
left a comment
There was a problem hiding this comment.
Three issues, here is some slop:
- Generic helpers stop compiling. A helper whose
idisT extends string | numbercan no longer callrouteUrl('/users/[id]', { params: { id } }). Forwarding typed options also breaks. Preserve the valid-call signature while adding diagnostic fallbacks. Signature- Valid objects with additional fields are rejected. Passing
const user = { id: 42, name: 'Alice' }as params now errors onname; passing aRouteDestinationas options also fails. These previously compiled and work at runtime. Preserve structural assignability. Validation- Invalid inputs can now bypass validation. A query typed
{ q: string } | { filter: { id: number } }compiles and serializes the object as[object Object]. Numeric param keys can also hide a missing requiredid, producing a runtime exception. Validate every union branch and avoid dropping numeric keys. Error calculation
|
Thanks I'll look into them. |
|
Some more issues as these calls compile now but throw at runtime: const userUrl = routeUrl.bind(undefined, '/users/[id]');
userUrl(); // Missing required id
userUrl({ params: { id: true } }); // Invalid id type
function forward(...args: Parameters<typeof routeUrl>) {
return routeUrl(...args);
} |
|
Thanks, doing more rounds of reviews and need to do more thorough testing |
371053e to
7e24fec
Compare
|
EDIT: Not yet ready. Overzealous AI went to mark it as ready and anyhow wrote a bunch of comments. |
Preserve required options for paths typed as any. Keep routeUrl diagnostics and function helper types while making generated route types compatible with Node16 CommonJS projects.
|
Ready for review. Please see the "Detailed error examples" section for examples of how the errors will look like now. I think there's a limit to how short the error messages can be, I tried to balance length and usefulness. |
|
One more issue: A generic wrapper loses per-route inference when you pass routeUrl through a logging helper that forwards (...args: A) => R. On main both |
Infer P and Candidate from the whole path argument so generic helpers such as `P & RoutePath` keep compiling. Keep the unknown-route marker from being a subtype of the path, so method signatures and code without strictFunctionTypes still reject unknown routes. Bound Candidate by plain string to avoid TS2590 in apps with more than ~316 route keys. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Infer the route candidate through a template literal, so only string literals produce one and generic paths such as `P & RoutePath` resolve like a plain parameter. This avoids TS2859 in apps with more than ~1,400 route keys. Keep P whole when every candidate is a known route, so paths such as `P | '/about'` still compile. Spell the unknown-route marker as a string literal. TypeScript then prints the argument as the path the caller wrote instead of `string`, and the marker still rejects unknown routes in bivariant parameter checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main type-checks test fixtures with tsrs. Keep the routeUrl tests' compiler matrix and add tsrs as its default entry, alongside TypeScript 7 and 6. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The diagnostics test parses `file(line,col): error` lines. Under FORCE_COLOR, which `vp run` sets for tests, TypeScript 7 and tsrs print pretty diagnostics even when tsconfig sets `pretty: false`, so pass `--pretty false` on the command line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Functions written to match `typeof routeUrl` with a `RoutePath` or generic path parameter, such as mocks and class members, stopped compiling: TypeScript could not show that the unknown-route marker is a route. Distribute the marker over the written path so its constraint reduces to `P`. Generated route declarations on main also exported the URL helper types (`TypedRoutes`, `RoutePathUrl` and others) from `void/routes`. Re-export them from the SDK. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem and behavior
When an app has static and dynamic routes,
routeUrl('/missing')can report an argument-count error. Unknown route literals now get a diagnostic on the path argument that names the unregistered pattern.routeUrl('/missing')routeUrl('/missing', {})Known routes use TypeScript's native diagnostics. Calling
routeUrl('/users/[id]')without options reports “Expected 2 arguments, but got 1.” A params object missingslugreports the required property directly.A single signature with a positional path preserves inference for generic wrappers and currying helpers, including helpers whose path is typed
P & RoutePathorP | '/about'. Forwarding withParameters, passing structural options, and using.bind(),.call(), and.apply()keep their checks. Unknown routes are also rejected where TypeScript compares parameters bivariantly: method signatures,implements, and projects withoutstrictFunctionTypes. As on the base branch, TypeScript allows assigning the unspecialized builder to a one-argument callback type for a dynamic route. Direct calls and a builder specialized asrouteUrl<'/users/[id]'>require options.Functions written to match
typeof routeUrl, such as mocks, test doubles, and class members, still compile when they type the path asRoutePath,string, or a genericP extends RoutePath. The URL helper types that generated declarations exported fromvoid/routeson main, such asTypedRoutesandRoutePathUrl, remain importable.The path check stays within TypeScript's union-size and relation-complexity limits (TS2590 and TS2859), which earlier revisions of this PR exceeded in apps with ~316 and ~1,400 route keys. An app with about 1,800 route keys type-checks in under 0.2 s with tsrs and TypeScript 7.0.2, and in about 0.4 s with TypeScript 6.0.3.
Generated URL declarations reference the installed SDK's canonical types through the stable
void/_route-url-typesexport. SDK type updates take effect without regenerating.void/routes.d.ts, including in apps using Node16 CommonJS or legacy Node module resolution. The maintainer guidance documents the export's compatibility requirement.Differences from main
The compatibility audit found four intended differences:
routeUrlto a method or function type whose parameter is a path literal now fails. On main it compiled because TypeScript compared the method's parameters bivariantly.routeUrlhas a second type parameter, sorouteUrl<'/about', '/about'>(...)now compiles. Calls with one type argument behave as before.routeUrldeclarations.typeof routeUrlthat types its options asRouteOptions<P>with its ownP, as in<P extends RoutePath>(path: P, options?: RouteOptions<P>) => ..., no longer compiles.routeUrlderives its options from the path as written, so an unknown route gets the path error, and that type differs from the path parameter's. Implementations with other option types, includingRouteOptions<RoutePath>, and contextually typed ones such as(path, ...options) => routeUrl(path, ...options)still compile.Detailed error examples
All 23 playground diagnostics
All 23 full compiler messages from tsrs 7.1.0-beta.tsrs2 and TypeScript 7.0.2 (identical) with
--noErrorTruncation. Line breaks are folded into spaces for the table.routeUrl('/missing');routeUrl('/missing', { query: { page: 1 } });routeUrl(uncheckedPath, {});routeUrl('/users/[id]');routeUrl('/users/[id]', { query: { tab: 'activity' } });routeUrl('/users/[id]', { params: {} });routeUrl('/users/[id]', { params: { userId: 42 } });routeUrl('/users/[id]', { params: { id: true } });routeUrl('/users/[id]', { params: { id: null } });routeUrl('/users/[id]', { params: { id: 42, extra: 'x' } });routeUrl('/about', { params: { id: 42 } });routeUrl('/blog/[category]/[slug]', { params: { category: 'typescript' } });routeUrl('/files/[...path]');routeUrl('/files/[...path]', { params: { path: false } });routeUrl('/users/[id]', { params: { id: [1, 2] } });routeUrl('/about', { query: { filter: { active: true } } });routeUrl('/about', { query: { tags: [{ name: 'typescript' }] } });routeUrl('/about', { hash: 123 });routeUrl('/about', { search: 'page=1' });routeUrl('/about', 'page=1');routeUrl('/users/[id]', { params: uncheckedParams });routeUrl('/about', { query });return routeUrl(path);Validation
typeof routeUrl(mocks, class members,satisfies, and default parameters), importing the URL helper types fromvoid/routes, generic options subtypes, wrapper and curry inference, genericP & RoutePathandP | '/about'paths, bivariant method and callback assignments with and withoutstrictFunctionTypes, an app with about 1,800 route keys, declaration emit and consumption, static-only function helpers, and explicit type arguments.skipLibCheckon and off, and an SDK upgrade with existing generated declarations.vpr test:allafter merging main passed formatting, lint, tsrs type checks across the workspace, and the platform and unit test groups (16,657 tests). In the integration group, 1,357 tests passed and the Astro PostgreSQL suite timed out waiting for its dev server on a loaded machine; rerunning that file passed all 8 tests. The 107 focused routing tests pass with all three compilers.The diagnostics playground and reports are local and gitignored.
🤖 Generated with Claude Code