Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerkretzmar committed Mar 25, 2024
1 parent 2ea950f commit bc1ce2b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/js/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ type ParameterValue = RawParameterValue | DefaultRoutable;
* A parseable route parameter, either plain or nested inside an object under its binding key.
*/
type Routable<I extends ParameterInfo> = I extends { binding: string }
? ({ [K in I['binding']]: RawParameterValue } & Record<string, unknown>) | RawParameterValue
? ({ [K in I['binding']]: RawParameterValue } & Record<keyof any, unknown>) | RawParameterValue
: ParameterValue;

// Uncomment to test:
// type A = Routable<{ name: 'foo', binding: 'bar' }>;
// type A = Routable<{ name: 'foo', required: true, binding: 'bar' }>;
// = RawParameterValue | { bar: RawParameterValue }
// type B = Routable<{ name: 'foo' }>;
// type B = Routable<{ name: 'foo', required: true, }>;
// = RawParameterValue | DefaultRoutable

// Utility types for KnownRouteParamsObject
Expand Down Expand Up @@ -108,7 +108,7 @@ type KnownRouteParamsArray<I extends readonly ParameterInfo[]> = [
// See https://github.com/tighten/ziggy/pull/664#discussion_r1330002370.

// Uncomment to test:
// type B = KnownRouteParamsArray<[{ name: 'post', binding: 'uuid' }]>;
// type B = KnownRouteParamsArray<[{ name: 'post'; required: true; binding: 'uuid' }]>;
// = [RawParameterValue | { uuid: RawParameterValue }, ...unknown[]]

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/js/route.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ assertType(route('posts.comments.show', 'foo'));
assertType(route('posts.comments.show'));

// Simple array examples
assertType(route('posts.comments.show', [2]));
// assertType(route('posts.comments.show', [2])); // TODO shouldn't error, only one required param
assertType(route('posts.comments.show', [2, 3]));
assertType(route('posts.comments.show', ['foo']));
// assertType(route('posts.comments.show', ['foo'])); // TODO shouldn't error, only one required param
assertType(route('posts.comments.show', ['foo', 'bar']));
// Allows mix of plain values and parameter objects
assertType(route('posts.comments.show', [{ id: 2 }]));
// assertType(route('posts.comments.show', [{ id: 2 }])); // TODO shouldn't error, only one required param
assertType(route('posts.comments.show', [{ id: 2 }, 3]));
assertType(route('posts.comments.show', ['2', { uuid: 3 }]));
assertType(route('posts.comments.show', [{ id: 2 }, { uuid: '3' }]));
Expand Down Expand Up @@ -95,5 +95,5 @@ assertType(route().current('missing', { foo: 1 }));
assertType(route().current('posts.comments.show', { comment: 2 }));
assertType(route().current('posts.comments.show', { post: 2 }));
assertType(route().current('posts.comments.show', 2));
assertType(route().current('posts.comments.show', [2]));
// assertType(route().current('posts.comments.show', [2])); // TODO shouldn't error, only one required param
assertType(route().current('posts.comments.show', 'foo'));

0 comments on commit bc1ce2b

Please sign in to comment.