Generate TypeScript types from SQL

Turn SQL column definitions into TypeScript interfaces with nullable fields.

freeworks offlinenothing uploaded
ToolSQL to TypeScript
Input
Output
Put this on your own site

The frame below runs the same code as this page, in the reader's own browser. Nothing is sent to us, and nothing is sent to you.

Pick a dark background and the text and panels follow it, so the frame stays readable on a dark page.

Preview

How it works

Column types map to TypeScript primitives or nullable unions, and table names become interfaces or aliases. Constraints are emitted as comments or optionality hints rather than runtime validation.

  • Common SQL primitives cover ordinary tables.
  • Null remains explicit because it differs from an omitted property.

Worked example

Generate TypeScript from SQL
Convert a CREATE TABLE statement to a TypeScript interface
Input
											CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(255) NOT NULL,
  created_at TIMESTAMP
);
										
Output
												// Generated from SQL CREATE TABLE statements

export interface Users {
  id: number;
  name: string;
  email: string;
  createdAt?: Date | null;
}
											

When to use this

API clients, migration schemas, and reporting endpoints generate result types.

Edge cases

  • DECIMAL can exceed JavaScript exact integer range.
  • Nullable is not the same as optional.
  • Database JSON and array types need project-specific mappings.

References