Slicemachine type generations for typescript projects

It would be great that from the models that we generate inside the slicemachine we would have the option to export the types for a typescript project.

5 Likes

Hi Bob,

Are describing something similar to what's being discussed here?:

We're also looking for better typescript integration, such as an interface definition alongside the model.json generated from Slice Machine.

Hi Jeremy,

I got a response from the team and they are not working on it at the moment, but the DevExp team plans to work on this after holidays.

Thanks.

1 Like

This thread has been closed due to inactivity. Flag to reopen.

Hello, this would still be relevant for us. Did make some progress on this? Thanks a lot!

Hi Marc,

There has been no progress on this for the moment, it's still planned but not being worked on. If/when this changes the team will update everyone here.

Thanks.

This is being tracked as an open feature request.

If you have another use-case for this feature, you can 'Flag' this topic to reopen. Please use the :heart: button to show your support for the feature and check out our Feature Request Guidelines.

Has there been any progress on this? This is super important. I think when you're developing on a team and using components that load in structured data from an external source, type safety should be a bigger priority and not treated as an after thought.

1 Like

Hello @rieraspotlight, thanks for joining the conversation. For the moment there’s no news about this feature request.

Any news on this? Given how deep the data structures go I'm a bit surprised this hasn't been done. If you could just view the type of a given document it'd speed up development 10fold

Additionally to this having spent more time with the product, I’ve grown like certain parts about the slice zone component generation.

It seems like the next step of this is to just make those auto generated components an index.tsx instead of ha alongside the types. Ofcourse that wouldn’t solve type generation for document types, but it’d be great for slices.

Hello @kyle2, thanks for joining the conversation. We don't have a fixed date for the release of these implementations, but we have opened the discussion about adding typescript support in Slice Machine. We would like to do this because it will allow us to type documents automatically for Slice Machine users in most cases, thanks to the plugin ecosystem. Whenever we have news about this being developed we'll announce it on our blog or progress page!

While this is supported by the slices machine, something that will help us is if Prismic would provide a standard Swagger/Open API or Graphql Schema so I can run swagger-typescript-api or Generate code from your GraphQL schema to get the types from the custom types of my repository into the project and manually use for each slice.

I know you provide API browser -> https://my-org.prismic.io/api/v2) and a GraphiQL -> https://my-org.prismic.io/graphql but can't really get them working with the previous code generators as I can't get the standard swagger.json or Graphql schema from your API Browser.

Getting those standard interfaces would allow me to run the generators again to get the generated ts updated anytime I made changes to the custom types in Prismic.

I tried following this link Custom Types API but it's not working.

Thanks in advance

@robertovg24 You can use the GraphQL introspection query to retrieve Prismic's GQL schema

{ __schema { types { kind name possibleTypes { name } } } }

I found this: GraphQL API introspecton/codegen - #11 by timur which actually looks like it's resolving what I'm facing. Thanks @Pau

BTW I would add this to the official documentation, so it's easier to type Prismic queries.

1 Like