whatisgithub

What is elm-ts-types?

lydell/elm-ts-types — explained in plain English

Analysis updated 2026-05-18

16JavaScriptAudience · developerComplexity · 2/5Setup · easy

In one sentence

A small library that generates TypeScript type definitions from compiled Elm JavaScript, covering flags, ports, and init functions.

Mindmap

mindmap
  root((elm-ts-types))
    What it does
      Generates TS types
      Types flags and ports
      Works with elm-watch
    Tech stack
      JavaScript
      TypeScript
      Elm
    Use cases
      Type safe Elm JS interface
      Catch port mistakes
      Automated d.ts generation
    Audience
      Elm developers
      TypeScript developers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Generate accurate .d.ts files for an Elm app's JavaScript interface automatically.

USE CASE 2

Catch mistakes like wrong flags or unsubscribed ports at compile time in a TypeScript project embedding Elm.

USE CASE 3

Wire elm-ts-types into an elm-watch build so type definitions regenerate on every build.

What is it built with?

JavaScriptTypeScriptElmNode.js

How does it compare?

lydell/elm-ts-typesadnpolymerase/ha-appliance-cardakaakshat246/ecoscore-browser-extension
Stars161616
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasyeasyhard
Complexity2/52/53/5
Audiencedevelopergeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

So what is it?

elm-ts-types is a small JavaScript library that solves a specific gap in the Elm programming language's tooling. Elm compiles to JavaScript, but once your Elm program becomes plain JavaScript, TypeScript has no way of knowing what functions it exposes, what flags it expects, or what data flows through its ports. This library fixes that by generating TypeScript type definitions directly from your compiled Elm code. You install it as an npm package and call its one function, generateTypeScript, passing it the compiled JavaScript string that the Elm compiler produced. It hands back a string of TypeScript definitions describing the app's init function, the flags it requires, and every port, including which ports send data and which ones subscribe to it, along with the exact shape of the data moving through each one. If you use the elm-watch build tool, this can run automatically as part of its build process so your type definitions stay up to date without extra effort. Once you save that output into a d.ts file, TypeScript recognizes the global Elm object in your project and understands exactly how to call into your Elm app safely, including catching mistakes like passing the wrong flags or forgetting to subscribe to a port. One detail worth knowing: subscribing to a port is typed to expect an async function rather than a plain one. This is intentional. Async functions in JavaScript never throw errors directly, they always return a promise and turn thrown errors into a rejected promise instead, which keeps an error in one port callback from silently breaking unrelated Elm commands running at the same time. Under the hood, the library works by injecting extra code into your compiled Elm output so that instead of actually starting the app, it returns information about its own structure, then evaluates that modified code to recover the true shape of your ports and flags. This keeps it automatically in sync with whatever the Elm compiler actually produces, rather than trying to parse Elm source code by hand.

Copy-paste prompts

Prompt 1
Show me how to call generateTypeScript from elm-ts-types on my compiled Elm JavaScript output.
Prompt 2
Help me wire elm-ts-types into my elm-watch postprocess step so .d.ts files regenerate automatically.
Prompt 3
Explain why elm-ts-types types port subscriptions as async functions instead of plain functions.
Prompt 4
Write the TypeScript code to subscribe to all the ports elm-ts-types generated for my Elm app.

Frequently asked questions

What is elm-ts-types?

A small library that generates TypeScript type definitions from compiled Elm JavaScript, covering flags, ports, and init functions.

What language is elm-ts-types written in?

Mainly JavaScript. The stack also includes JavaScript, TypeScript, Elm.

How hard is elm-ts-types to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is elm-ts-types for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.