---
url: https://node-ts.github.io/bus/api/bus-cli/functions/generateMessageTypes.md
---
[API reference](../../index.md) / [@node-ts/bus-cli](../index.md) / generateMessageTypes

# Function: generateMessageTypes()

```ts
function generateMessageTypes(options?): GeneratedMessageTypes;
```

Defined in: [packages/bus-cli/src/generate-message-types/generate-message-types.ts:102](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-cli/src/generate-message-types/generate-message-types.ts#L102)

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

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `options` | [`GenerateMessageTypesOptions`](../interfaces/GenerateMessageTypesOptions.md) | where the project is and which files to read |

## Returns

[`GeneratedMessageTypes`](../interfaces/GeneratedMessageTypes.md)

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)
```
