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

Link variants should be typable with a generic #372

Open
lihbr opened this issue Jan 14, 2025 · 1 comment
Open

Link variants should be typable with a generic #372

lihbr opened this issue Jan 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@lihbr
Copy link
Member

lihbr commented Jan 14, 2025

Versions

  • @prismicio/client: 7.14.0
  • node: 22.0.0

Steps to reproduce

  1. Create a link field with variants with Slice Machine
  2. Check out generated TypeScript

What is expected?

Link variants should be precisely typed when available values are known (always the case for a link field typed after a custom type definition)

This starts by allowing the LinkField type to support another generic to type available variants beyond string but it's not really ideal without reordering generics today (which would be a breaking change).

From here, prismic-ts-codegen could leverage the generic to type variants more precisely the same way it does it for other generic-dependant types (e.g. constrained content relationships)

What is actually happening?

Generated types

{
  navigation: prismic.Repeatable<prismic.LinkField>;
}

Result
Image

Source code

export type OptionalLinkProperties = {
text?: string
variant?: string
}

@lihbr lihbr added the bug Something isn't working label Jan 14, 2025
@angeloashmore
Copy link
Member

The field value types should primarily be consumed via the generated types rather than handwritten types. Adding another generic seems okay to me. Re-ordering should be avoided, however, as it would break existing generated types.

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