Closed scmx closed 5 months ago
As discussed in PR https://github.com/dohomi/storyblok-generate-ts/pull/45 @davidhoeck changed it to string. I am honestly not sure whats the right approach.. currently I cast a lot of string => number but its been a while since I worked with Storyblok
I created a new number field and with every configuration the output was a string. So I don't think that Storyblok returns int or float values at all.
An example:
The JSON:
The Field:
The Field config:
Any progress on this, Please help.
you have to manually cast your number fields inside your components from string => number. Thats currently the only way as the response from the Storyblok API is of type string.
Hi 👋 I noticed the recent change "Parse numbers to string type" #45 to change numeric fields to have type string in the resulting interface. This might not be correct. For me the numeric field values have always been given as number literals from api and storyblok-js-client.
Perhaps the data you looked at was a field that had type string and was changed to numeric, and there might be some bug resulting in you continuing to get it as a string because of the previous type?
Some ideas: Maybe a jsdoc comment could be generated that shows the storyblok type of each field.
If we can verify that the value is sometimes a number then maybe consider having
string | number
as generated type. Consumers would still need to wrap each usage withNumber(blok.field)
but at least you see that it might already be a string.