Typescript Types for Blocks #988
Replies: 3 comments
-
I was kind of surprised to see this isn't a thing already considering it's needed for almost every project using blocks. Even Payloads own website has a sort of hacky way to accomplish this though that kind of breaks if you don't have all blocks within one collection. So yeah, BIG +1 on this issue from me! |
Beta Was this translation helpful? Give feedback.
-
Would love to see this as well. Currently writing the interface definitions by hand alongside my blocks. |
Beta Was this translation helpful? Give feedback.
-
Not an optimal solution, but it's possible to access a block type by picking it from a generated globals/collection, you can see an example here: #1563 (comment). If each payload's block correspond to a component in your app, you can also make a mapping and auto bind the types. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently the
generate:types
creates named types for all my collections, with blocks being typed inline.Because I have many components that just handle rendering a single Block, I have to manually add named Block types in order to have a clean Typescript Interface.
It would be really helpful if the type generation could include blocks and also the general types of a block and a collection, to have a more complete interface in the client.
Example:
My collections:
My blocks:
Current output includes only the types:
ContentPage, Icon
but should ideally include:
Collection, ContentPage, Icon, Block, IconUspList, Accordion, Headline
Is this something you think could be included? Or is it already possible and I just haven't figured out how?
Thanks & Cheers
Beta Was this translation helpful? Give feedback.
All reactions