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

Unable to provide a boolean to predicates #229

Closed
angeloashmore opened this issue Mar 17, 2022 · 2 comments
Closed

Unable to provide a boolean to predicates #229

angeloashmore opened this issue Mar 17, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@angeloashmore
Copy link
Member

Predicates are typed to only accept strings and numbers (and arrays of those) by default.

If a predicate refers to a Boolean field, however, a boolean value is needed.

See this Prismic Community thread for more details: https://community.prismic.io/t/typescript-error-when-using-booleans-in-predicates/9391

Versions

  • @prismicio/client: v6.4.1
  • node: v14.18.1

Reproduction

import { predicate } from '@prismicio/client'

predicate.at('my.blog_post.is_hidden', true)
// TypeScript complains that predicate.at() doesn't accept a boolean value in the second argument

Steps to reproduce

Run the above code snippet.

What is expected?

Predicates accept boolean values.

What is actually happening?

The code runs correctly (i.e. it handles booleans in the final API URL), but TypeScript says it is invalid.

@angeloashmore angeloashmore added the bug Something isn't working label Mar 17, 2022
@lihbr lihbr closed this as completed in f15f606 Mar 23, 2022
@lihbr
Copy link
Member

lihbr commented Mar 23, 2022

Here you go, I also added date support and refined types so it's less generic and closer to what the API expects: f15f606

I went ahead and released the patch for it as it was quite straightforward. Feel free to look at code changes in the above commit if needed.

@angeloashmore
Copy link
Member Author

angeloashmore commented Mar 23, 2022

Awesome, that looks great! And nice catch on including Date.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants