From a27e388397c48f4e3fdf35971aab595904223766 Mon Sep 17 00:00:00 2001 From: Aryaman Dhingra Date: Fri, 23 Aug 2024 10:36:45 -0400 Subject: [PATCH] feat: add type error if path doesn't start with / DX-703 --- packages/io-ts-http/src/httpRoute.ts | 4 +++- packages/superagent-wrapper/src/request.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/io-ts-http/src/httpRoute.ts b/packages/io-ts-http/src/httpRoute.ts index a2384299..f18aed71 100644 --- a/packages/io-ts-http/src/httpRoute.ts +++ b/packages/io-ts-http/src/httpRoute.ts @@ -13,8 +13,10 @@ export const Method = t.keyof({ export type Method = t.TypeOf; +export type PathString = `/${string}`; + export type HttpRoute = { - readonly path: string; + readonly path: PathString; readonly method: Uppercase; readonly request: HttpRequestCodec; readonly response: HttpResponse; diff --git a/packages/superagent-wrapper/src/request.ts b/packages/superagent-wrapper/src/request.ts index 41d9dd5e..3b53189e 100644 --- a/packages/superagent-wrapper/src/request.ts +++ b/packages/superagent-wrapper/src/request.ts @@ -201,7 +201,7 @@ export const requestForRoute = let path = route.path; for (const key in reqProps.params) { if (reqProps.params.hasOwnProperty(key)) { - path = path.replace(`{${key}}`, reqProps.params[key]); + path = path.replace(`{${key}}`, reqProps.params[key]) as h.PathString; } }