Newt is a domain specific language that compiles to Typescript type code. Newt is not for general purpose programming, but rather for creating toys/abominations in the TS type system.
Fundamentally, Newt is designed to provide more ergonomics around conditional types.
Take, for instance the following typescript expression:
interface IdLabel {
id: number
}
interface NameLabel {
name: string
}
type IdOrNameLabel<T extends string | number> =
T extends string
? NameLabel
: IdLabel;The same thing can be expressed in Newt using different control structures:
interface IdLabel {
id: number
}
interface NameLabel {
name: string
}
type IdOrNameLabel(T)
where T <: string | number
do
if T <: string then
NameLabel
else
IdLabel
end
endOr
type IdOrNameLabel(T)
where T <: string | number
do
cond do
T <: string -> NameLabel
else -> IdLabel
end
endOr finally:
type IdOrNameLabel(T)
where T <: string | number
do
match T do
string -> NameLabel
_ -> IdLabel
end
endWhile these simple examples probably aren't too compelling given all the extra characters, this get much more useful as your type programs get more complicated.
The easiest way to get started is to check out some of the examples or tests.
Refer to ./mise.toml for all build, dev, and test commands.