Joe Hoyle

WP REST API TypeScript Generator

This is a tool to generate TypeScript Types for all objects and request arguments from your site's WordPress REST API. As each WordPress site can have it's own set of endpoints and object types (provided by plugins and custom API endpoints), it's often neccesary to have the types specific to the site's API rather than a generic set of WordPress types.

The generator works by crawling your WordPress site's REST API base and inspecting all schema properties of all endpoints. Enter your WordPress site URL below to generate types.

Currently this supports creating TypeScript types for all object types (such as post, page, etc), and object base route request arguments, such as wp/v2/posts.

Object types are transformed from snake-case to pascal case, for example menu-item becomes type MenuItem.

Object base route request arguments are similarily converted. The endpoint GET /wp/v2/posts will generate a type GetPostsRequestArguments and POST /wp/v2/pages will generate a TypeScript type of CreatePostRequestArguments.

In the future I'd like to release this as a package so developers can run it locally too.

Follow me on twitter to get future updates@joe_hoyle