Skip to content
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

toDate() method with "." literal returns never #2

Open
tomferez opened this issue Oct 7, 2024 · 3 comments
Open

toDate() method with "." literal returns never #2

tomferez opened this issue Oct 7, 2024 · 3 comments

Comments

@tomferez
Copy link

tomferez commented Oct 7, 2024

Hi,

When using the toDate() method with a IntlDateFormatter that uses a "." on a field level, the returned type is never.

Example: date: "page.date.toDate('d.m.Y')" returns "never" - iso "string | number".

Am no expert of Typescript so couldn't really help with the issue...

Thanks!
Tom

@benwest
Copy link
Owner

benwest commented Oct 10, 2024

Hi! Cool that you’re using the library 😃

You’re right that the dots are causing the problem. I think you should be able to write date: "page.date.toDate('d.m.Y')" as "page.date.toDate" to get around it.

@tomferez
Copy link
Author

Yes I'm using it because the lack of "native" Typescript support is really what's preventing me from using KirbyCMS in a prod level with headless.

I think you should be able to write date: "page.date.toDate('d.m.Y')" as "page.date.toDate" to get around it.

I thought of that, but then you lose the ability to format the date through the query. No big deal though... ☺️

@benwest
Copy link
Owner

benwest commented Oct 14, 2024

I thought of that, but then you lose the ability to format the date through the query. No big deal though... ☺️

no!- you're sending the same query, the as is a type hint.

But for what it's worth I've gone back to using zod myself to validate types because of this kind of thing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants