A PR merged back in April changed the type of Params, allowing numbers to be provided in addition to strings. See https://github.com/withastro/astro/pull/3087. However, as said PR changed the type of Params instead of GetStaticPathsItem, it also affects Astro.params. This commit moves the change to GetStaticPathsItem, reverting the type of Astro.params.
This commit is contained in:
parent
5e693c2143
commit
731e99df87
3 changed files with 10 additions and 5 deletions
5
.changeset/nervous-laws-knock.md
Normal file
5
.changeset/nervous-laws-knock.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Narrow type of `Params`, as its values cannot be numbers
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue