Cédric Chantepie
3 Feb 2021
•
1 min read
Scala-TS is a simple tool which generates TypeScript types from Scala types.
For example, with a Scala case class as below,
case class Incident(id: String, message: String)
It generates the appropriate TypeScript:
export interface Incident {
id: string;
message: string;
}
const incident: Incident = {
id: 'id',
message: 'A message'
}
Scala-TS now supports a lot a type kinds: generic class, Value class, sealed trait, enumeration, union type.
See more examples
It's useful to share model between Scala and TypeScript (e.g.across REST API).
This new major release 0.5.0 provide easy to use, but yet highly configurable & extensible compiler and SBT plugins to generate TypeScript types from Scala compiled one.
It can be configured by adding to project/plugins.sbt
:
addSbtPlugin("io.github.scala-ts" % "sbt-scala-ts" % "0.5.0")
Then the plugin can be enabled per project:
// Not enabled by default
enablePlugins(TypeScriptGeneratorPlugin)
The TypeScript files are generated at compile-time.
sbt compile
See documentation
Cédric Chantepie
Cédric Chantepie is IT architect, with varied development experience, obsessed by software quality (CI, testing, ...) and involved in open source projects.
See other articles by Cédric
Ground Floor, Verse Building, 18 Brunswick Place, London, N1 6DZ
108 E 16th Street, New York, NY 10003
Join over 111,000 others and get access to exclusive content, job opportunities and more!