Skip to content

Astro.params.foo is typed as string|number|undefined, but it can only be string|undefined, which forces extra TypeScript typing  #5442

@jyasskin

Description

@jyasskin

What version of astro are you using?

1.6.10

Are you using an SSR adapter? If so, which one?

node

What package manager are you using?

npm

What operating system are you using?

Linux (WSL)

Describe the Bug

export type Params = Record<string, string | number | undefined>;
says that Astro.params can contain numbers, which https://docs.astro.build/en/reference/api-reference/#params says doesn't actually happen. This forces TypeScript programs to either handle a number type that never actually happens or to cast it away.

I believe #3087 introduced this in order to loosen typing in getStaticPaths(), which produces Params instances, but it broke consumption of the types. You probably need two different types for inbound vs outbound.

Run astro check in https://stackblitz.com/edit/github-fht7tc?file=src/pages/products/[name].astro to see the error.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-fht7tc?file=src/pages/products/[name].astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P2: nice to haveNot breaking anything but nice to have (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions