summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/nervous-laws-knock.md5
-rw-r--r--packages/astro/src/@types/astro.ts4
-rw-r--r--packages/astro/src/core/routing/params.ts6
3 files changed, 10 insertions, 5 deletions
diff --git a/.changeset/nervous-laws-knock.md b/.changeset/nervous-laws-knock.md
new file mode 100644
index 000000000..b9b979fb9
--- /dev/null
+++ b/.changeset/nervous-laws-knock.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Narrow type of `Params`, as its values cannot be numbers
diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts
index d24b194c8..b0b19eb17 100644
--- a/packages/astro/src/@types/astro.ts
+++ b/packages/astro/src/@types/astro.ts
@@ -1047,7 +1047,7 @@ export type GetHydrateCallback = () => Promise<() => void | Promise<void>>;
rss(): never;
}
-export type GetStaticPathsItem = { params: Params; props?: Props };
+export type GetStaticPathsItem = { params: { [K in keyof Params]: Params[K] | number }; props?: Props };
export type GetStaticPathsResult = GetStaticPathsItem[];
export type GetStaticPathsResultKeyed = GetStaticPathsResult & {
keyed: Map<string, GetStaticPathsItem>;
@@ -1146,7 +1146,7 @@ export interface Page<T = any> {
export type PaginateFunction = (data: any[], args?: PaginateOptions) => GetStaticPathsResult;
-export type Params = Record<string, string | number | undefined>;
+export type Params = Record<string, string | undefined>;
export interface AstroAdapter {
name: string;
diff --git a/packages/astro/src/core/routing/params.ts b/packages/astro/src/core/routing/params.ts
index 0b9275170..6a822861f 100644
--- a/packages/astro/src/core/routing/params.ts
+++ b/packages/astro/src/core/routing/params.ts
@@ -1,4 +1,4 @@
-import type { Params } from '../../@types/astro';
+import type { GetStaticPathsItem, Params } from '../../@types/astro';
import { validateGetStaticPathsParameter } from './validation.js';
/**
@@ -27,12 +27,12 @@ export function getParams(array: string[]) {
* values and create a stringified key for the route
* that can be used to match request routes
*/
-export function stringifyParams(params: Params, routeComponent: string) {
+export function stringifyParams(params: GetStaticPathsItem['params'], routeComponent: string) {
// validate parameter values then stringify each value
const validatedParams = Object.entries(params).reduce((acc, next) => {
validateGetStaticPathsParameter(next, routeComponent);
const [key, value] = next;
- acc[key] = typeof value === 'undefined' ? undefined : `${value}`;
+ acc[key] = value?.toString();
return acc;
}, {} as Params);