Using Yellicode in a TypeScript project

You might want to use Yellicode templates, written in TypeScript, to generate TypeScript code. This could cause your code generation code and other TypeScript code - with different compilation requirements - to get in each other's way. If you compile all your project's TypeScript code using a configuration that is incompatible with Node.js (Yellicode runs on Node.js), your code generation process could throw errors or yield unexpected results. Here are some options to get around this:

1. Separate your code generation project into its own directory

The simplest way around this is to have your code generation project separated from the directories where the output should be generated. For example, consider the following structure:

- my-app
    - src
        - example.output.ts
- codegen
    - package.json
    - codegenconfig.json
    - example.template.ts

Then, in example.template.ts, make sure to set the output location to ../my-app/src/example.output.ts

Generator.generate({ outputFile: '../my-app/src/example.output.ts' }, (writer: TextWriter) => {
    // code generation logic goes here...

This results in a clean separation between both projects, each with its own TypeScript configuration, package.json file and corresponding node_modules directory.

2. Excluding templates from default compilation

In order to avoid code generation errors, your templates should be excluded from the default TypeScript compilation of your application. Therefore, it is recommended to follow a naming convention for all your templates, for example by ending each template name with .template.ts. Then, in your application's tsconfig.json, ensure that the exclude section contains the following:

    "compilerOptions": {
        // left out for brevity
    "exclude": [

This will make sure that code generation templates are not compiled by default and will only be compiled by Yellicode instead. If you need more control over how templates are compiled, please refer to Configuring TypeScript.