Skip to content

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

You can convert any existing script to typescript by changing the file name extension to .genai.mts.

summarizer.mts
def("FILE", files)
$`Summarize each file. Be concise.`

Importing TypeScript source files

It is possible to import TypeScript source file using dynamic imports.

summarizer.mts
export function summarize(files: string[]) {
def("FILE", files)
$`Summarize each file. Be concise.`
}
  • dynamic import (async import(...))
const { summarize } = await import("./summarizer.mts")
summarize(env.generator, env.files)

Does GenAIScript typecheck prompts?

No.

GenAIScript converts TypeScript to JavaScript without type checks through tsx.

Most modern editors, like like Visual Studio Code, will automatically typecheck TypeScript sources.