
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.`
Importing TypeScript source files
Section titled “Importing TypeScript source files”It is possible to import TypeScript source file.
export function summarize(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 automatically type-check TypeScript sources.
You can also run a TypeScript compilation using the scripts compile
command.
genaiscript scripts compile
However, at runtime, GenAIScript converts TypeScript to JavaScript without type checks through tsx.