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 |
Problem and behavior
With
typedRoutes: true, an unknown route or a route called without its required options can produce a misleading argument-count error. This adds custom guidance for those cases and for unchecked string paths. Known routes with options retain TypeScript's native property and value errors, which show the required types directly.Given
/aboutand/users/[id], the relevant diagnostic excerpts change as follows:routeUrl('/missing')routeUrl('/users/[id]')Known-route option errors remain native. For example:
The public
routeUrl(path, options)API and valid-call contract are preserved, including callbacks for static routes, generic helpers, structural objects with extra fields, and specialized or unspecializedParametersforwarding. Apps with dynamic routes still require options for paths typed asany.Parameters,.bind(),.call(), and.apply()keep the checked signature, and explicit route type arguments remain constrained to registered patterns. Route, option, and param autocomplete remain intact.Generated URL declarations reference the installed SDK's canonical types through the stable
void/_route-url-typesexport, including under Node16 CommonJS and legacy Node module resolution. This lets SDK type updates take effect without regenerating.void/routes.d.ts. The export's compatibility requirement is documented in the package maintainer guidance.TypeScript's overload heading remains for calls with options. Generic path-only calls can still produce verbose conditional-type diagnostics. Raw URL diagnostics remain for a separate PR.
Detailed error examples
All 23 playground diagnostics
All 23 full compiler messages from TypeScript 7.0.2 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 });routeUrl(path);Validation
anypaths, generic params, structural extra fields, generic and unspecialized forwarding, function helpers, widened explicit route types, invalid query unions, numeric and symbol keys, exact optional properties, and attempts to pass diagnostic types as valid inputs.params/query/hashfor options, and the correct param names.skipLibCheck: falseon TypeScript 6 and 7. Legacy Node resolution retains route checks withskipLibCheckon or off. Upgrade regressions change the installed SDK query contract and remove the old installation while keeping generated declarations unchanged.The ad-hoc diagnostics playground and its generated reports are gitignored and are not included in this PR.