elm-types
v0.0.2elm-types
TypeScript type definitions for Elm bundled applications.
npm install -D elm-types
Usage:
- First create type definitions for your application:
// App.ts
import * as Elm from 'elm-types'
export type App = Elm.Document<Flags, Ports>
export type Flags = {}
export type Ports = Elm.Ports<{
sayHello: Elm.IncomingPort<string>
}>
- Then type definitions for the .elm file. This only applies if you are using a bundler such as Parcel, Webpack, Rollup, etc, where you import the .elm file directly:
// App.elm.d.ts (must be placed next to your App.elm file)
import {Bundle} from 'elm-types'
import {App} from './App.ts'
export const Elm: Bundle<{App: App}>
- Finally import the .elm file. If everything worked correctly, all the code below will be correctly typed.
// main.ts
import {Elm} from './App.elm'
const app = Elm.App.init({
flags: {}
})
app.ports.sayHello.send('Hello from TypeScript!')
Check out example/
for a complete setup using Parcel.