Skip to content

Commit d6fc087

Browse files
committed
Rename Extract to VarName, since Extract is a built in type
1 parent 0bf77c2 commit d6fc087

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

spec/common/params.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE ignoreUnusedWarning OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
import { Extract, ParamsOf, Split } from "../../src/common/params";
23+
import { VarName, ParamsOf, Split } from "../../src/common/params";
2424
import { expectNever, expectType } from "./metaprogramming";
2525

2626
describe("Params namespace", () => {
@@ -56,21 +56,21 @@ describe("Params namespace", () => {
5656
});
5757
});
5858

59-
describe("Extract", () => {
59+
describe("VarName", () => {
6060
it("extracts nothing from strings without params", () => {
61-
expectNever<Extract<"uid">>();
61+
expectNever<VarName<"uid">>();
6262
});
6363

6464
it("extracts {segment} captures", () => {
65-
expectType<Extract<"{uid}">>("uid");
65+
expectType<VarName<"{uid}">>("uid");
6666
});
6767

6868
it("extracts {segment=*} captures", () => {
69-
expectType<Extract<"{uid=*}">>("uid");
69+
expectType<VarName<"{uid=*}">>("uid");
7070
});
7171

7272
it("extracts {segment=**} captures", () => {
73-
expectType<Extract<"{uid=**}">>("uid");
73+
expectType<VarName<"{uid=**}">>("uid");
7474
});
7575
});
7676

src/common/params.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ export type NullSafe<S extends null | undefined | string> = S extends null
6060
* A type that extracts parameter name enclosed in bracket as string.
6161
* Ignore wildcard matches
6262
*
63-
* For example, Extract<"{uid}"> is "uid".
64-
* For example, Extract<"{uid=*}"> is "uid".
65-
* For example, Extract<"{uid=**}"> is "uid".
63+
* For example, VarName<"{uid}"> is "uid".
64+
* For example, VarName<"{uid=*}"> is "uid".
65+
* For example, VarName<"{uid=**}"> is "uid".
6666
*/
67-
export type Extract<Part extends string> = Part extends `{${infer Param}=**}`
67+
export type VarName<Part extends string> = Part extends `{${infer Param}=**}`
6868
? Param
6969
: Part extends `{${infer Param}=*}`
7070
? Param
@@ -90,7 +90,7 @@ export type ParamsOf<PathPattern extends string | Expression<string>> =
9090
// N.B. I'm not sure why PathPattern isn't detected to not be an
9191
// Expression<string> per the check above. Since we have the check above
9292
// The Exclude call should be safe.
93-
[Key in Extract<
93+
[Key in VarName<
9494
Split<NullSafe<Exclude<PathPattern, Expression<string>>>, "/">[number]
9595
>]: string;
9696
};

0 commit comments

Comments
 (0)