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

# Function: mergeMessageTypes()

```ts
function mergeMessageTypes(messageTypes): MessageTypes;
```

Defined in: [packages/bus-messages/src/merge-message-types.ts:66](https://github.com/node-ts/bus/blob/2e6cf65c27833b707ae31ee623cfb6343770f434/packages/bus-messages/src/merge-message-types.ts#L66)

Merges the message types of several message libraries into one, as the bus does with the message
types passed to `withMessageTypes()`. Nothing is shared between calls, so each bus has its own.

Passing the same message types more than once is the same as passing them once.

## Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `messageTypes` | [`MessageTypes`](../interfaces/MessageTypes.md)\[] | the message types to merge, usually the `messageTypes` export of each file generated by `bus generate-message-types` |

## Returns

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

the merged message types

## Throws

MessageTypeReferenceNotFound if some message types refer to a type they don't define

## Throws

MessageTypesConflict if two of them define a `$name` or type key differently

## Example

```ts
import { messageTypes as orderMessageTypes } from '@my-org/order-messages'
import { messageTypes } from './message-types.generated'

const merged = mergeMessageTypes([orderMessageTypes, messageTypes])
```
