
TypeScript
TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. GenAIScript scripts can be authored in TypeScript.
From JavaScript to TypeScript
Section titled “From JavaScript to TypeScript”You can convert any existing script to typescript by changing the file name extension to.genai.mts
.
def("FILE",files)$`Summarize each file. Be concise.`
Make sure to use the.mts
file extension - not.ts
-, which forces Node.JS to use theESM module system.
Importing TypeScript source files
Section titled “Importing TypeScript source files”It is possible toimport TypeScript source file.
exportfunctionsummarize(files:string[]) {def("FILE",files)$`Summarize each file. Be concise.`}
- import
import { summarize }from"./summarizer.mts"summarize(env.generator,env.files)
Does GenAIScript type-check prompts?
Section titled “Does GenAIScript type-check prompts?”Yes and No.
Most modern editors, like Visual Studio Code, will automaticallytype-check TypeScript sources.
You can also run a TypeScript compilation using thescripts compile
command.
genaiscriptscriptscompile
However, at runtime, GenAIScript converts TypeScript to JavaScriptwithout type checks throughtsx.