Skip to content

Commit 5c3c3b7

Browse files
authored
Fix combination of params and captures (#1242)
1 parent d26a2c8 commit 5c3c3b7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

spec/common/params.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,15 @@ describe("Params namespace", () => {
9595
log: "world",
9696
} as const);
9797
});
98+
99+
it("extracts strings with params interpolated", () => {
100+
// NOTE: be wary of this test. Hover over the types to see what they're
101+
// parsing as. When doing TDD this test surprisingly passed. That's
102+
// because ParamsOf was returning the empty interface because it did
103+
// not special case for Record<string, never>. This meant that any input
104+
// would pass the test. Fixing this issue in the test suite is as copmlex
105+
// as fixing the bug to begin with and would probably share implementations.
106+
expectType<ParamsOf<`${string}/{uid}`>>({ uid: "uid" });
107+
});
98108
});
99109
});

src/common/params.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export type Split<S extends string, D extends string> =
3636
S extends `${D}${infer Tail}`
3737
? [...Split<Tail, D>]
3838
: S extends `${infer Head}${D}${infer Tail}`
39-
? [Head, ...Split<Tail, D>]
39+
? // Drop types that are exactly string; they'll eat up literal string types
40+
string extends Head
41+
? [...Split<Tail, D>]
42+
: [Head, ...Split<Tail, D>]
4043
: // A string without delimiters splits into an array of itself
4144
[S];
4245

0 commit comments

Comments
 (0)