Working with types¶
In Superglue, there's no need to annotate your types in ruby just to regenerate
them in typescript. Instead you write typescript first and let runtime type
validation give you the developer feedback to build your props.
To get started, run the installation generator with the typescript flag.
The installation generator will add
- a esbuild plugin that enables deepkit to work with Superglue
- a build.mjs, a esbuild node script that builds your application.
- And setup deepkit to work with esbuild. If you are using vite or bun with superglue, please use deepkit/vite or deepkit/bun plugins.
How It Works¶
Superglue uses Deepkit for runtime type validation during development:
- Build Time: Deepkit's compiler transforms TypeScript types into runtime validation code
- Development Mode:
useContent()validates server responses against your types - Production Mode: Validation code is stripped entirely
Writing your types¶
useContent is the generic hook used to access the props you
build. To make use of runtime types, simply pass a type
describing your page's props as you normally would:
For example:
import React from 'react'
import { useContent } from '@thoughtbot/superglue'
interface Post {
id: number
title: string
content: string
}
type PostShowProps = {
header: string;
post: Post;
}
export default function PostShow() {
const { header, post} = useContent<PostShowProps>()
return (
<div>
<h1>{header}</h1>
<ul>
<li>{post.id}</li>
<li>{post.title}</li>
<li>{post.content}</li>
</ul>
</div>
)
}
If the payload from app/views/posts/show.json.props was mishaped in anyway, you'd get an error:

Use that error and feedback loop to build your props: