Skip to content

API reference / @node-ts/bus-cli / generateMessageTypes

Function: generateMessageTypes() ​

ts
function generateMessageTypes(options?): GeneratedMessageTypes;

Defined in: packages/bus-cli/src/generate-message-types/generate-message-types.ts:102

Reads the messages and workflow state declared in a TypeScript project, and generates the source of a file that maps each $name to how its fields are restored from JSON. Pass the file's messageTypes export to Bus.configure().withMessageTypes(). The project is only read, like tsc --noEmit, with the project's own copy of TypeScript, and nothing is written.

Parameters ​

ParameterTypeDescription
optionsGenerateMessageTypesOptionswhere the project is and which files to read

Returns ​

GeneratedMessageTypes

the generated source, where to write it, and warnings about the project

Throws ​

TypeScriptNotFound if the project doesn't have TypeScript installed

Throws ​

MessageTypeGenerationFailed if the project can't be read, or a message has a type that can't be restored from JSON

Example ​

ts
const { outFile, content } = generateMessageTypes({ entry: ['src/messages/**/*.ts'] })
writeFileSync(outFile, content)

Released under the MIT License.