-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When creating a page with getStaticPaths
which return a number
param, later Astro.params
returns a string
#4309
Comments
Also trying with explicit typing the
|
|
Hi @matthewp , thx for giving feedback. I'm wondering if
Also note this PR , merged earlier this year:
Although I now also notice this: ❯ npm run dev
🚀 astro v1.0.5 started in 54ms ┃ Local http://localhost:3000/ 08:03:12 PM [getStaticPaths] invalid path param: year. A string value was expected, but got I get this with:
which is basically similar as https://github.com/withastro/astro/blob/main/packages/astro/test/fixtures/astro-get-static-paths/src/pages/blog/%5Byear%5D/%5Bslug%5D.astro I took your suggestion using
This works. No warning/errors about "A string value was expected" and the But it feels a bit clumsy ... |
Oh, let me reopen, it looks like the history is more complex than I thought. |
Thx Matthew, The docs also state:
So just to summarise, I see 2 issues: (1) Using a
(2) Using a |
Can it be confirmed if this is a bug or intended behavior? And maybe label the issue accordingly? |
The warning you're seeing I'm not sure about and will need to keep investigating. I would think that it should be ok to return a number but perhaps I am missing something. |
Yes for SSR I fully understand, not for SSG. And I can also understand to take the Maybe @natemoo-re @bholmesdev @tony-sull can chip in about that typing change in the merged PR #3087 |
@marceloverdijk Ah, was just asking myself this same question! It looks that PR allows numeric I agree this half-support for numeric params is confusing though; if I as a maintainer am unsure, I can only imagine how users feel 😅 @tony-sull any thoughts on this? |
I think the original motivation behind #3087 was to clean up a common pain point we were seeing in support threads at the time, there were a number of users trying to either use page numbers or dates in The idea was to allow I think any change here to |
08:39:10 PM [getStaticPaths] invalid path param: year. A string value was expected, but got `1990`.
08:39:10 PM [getStaticPaths] invalid path param: year. A string value was expected, but got `1991`.
08:39:10 PM [getStaticPaths] invalid path param: year. A string value was expected, but got `1992`. Short term I think we should probably clean up this error message. I wouldn't have expect this to log since |
OK clear, So with the current half-support I think I should use simply This is what I have now:
The output in the page is an example btw ;-) ps: the way I defined the type sage Params, is that the most straightforward way to do it? By extending |
@marceloverdijk That looks good to me! We'll clean up the logs so you don't have to use
|
Indeed the This works as well:
The clean-up of the logs would be nice indeed and I think I can change:
to
as that |
|
Awesome, thank you @rishi-raj-jain ! |
Hello, I am actually seeing a very similar thing. I am trying to create a SSR slug route, and when trying to access the slug, TS identifies this as string | number, causing some warnings down the line. Using pnpm, version 1.5.3, platform: mac EDIT: As far as I can see the type declaration is
|
What version of
astro
are you using?1.0.5
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Mac
Describe the Bug
When creating a page with
getStaticPaths
which return anumber
param, laterAstro.params
returns astring
.when accessing
/seasons/1990
this prints:although expected:
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ydxdyc?file=src/pages/seasons/[year].astro
Participation
The text was updated successfully, but these errors were encountered: