# registerConverter Function

Module
import { registerConverter } from "@tsed/common/src/converters/registries/ConverterRegistries"
Source/packages/common/src/converters/registries/ConverterRegistries.ts

# Overview

const registerConverter: (provider: any, instance?: any) => void;

# Description

Add a new converter in the ProviderRegistry. This converter will be built when InjectorService will be loaded.

# Example

import {registerConverter, InjectorService} from "@tsed/common";

export default class MyConverter {
    constructor(){}
    serialize() {
        return "test";
    }
}

registerConverter({provide: MyConverter});
// or
registerConverter(MyConverter);

const injector = new InjectorService();
injector.load();

const myConverter = injector.get<MyConverter>(MyConverter);
myConverter.serialize(); // test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18