cevek / ttypescript

Over TypeScript tool to use custom transformers in the tsconfig.json
1.53k stars 56 forks source link

Bug fix for "Expression produces a union type that is too complex to represent" error #112

Closed mdmitry01 closed 2 years ago

mdmitry01 commented 3 years ago

Hi! I use ttypescript package in a private project. When I compile the project using tsc, I have no compilation errors. But when I use ttsc (note the double t in the name), I get a strange error: Expression produces a union type that is too complex to represent . I found out that the cause of this error is in this library.

ttypescript replaces emit method https://github.com/cevek/ttypescript/blob/505e3aa95e26b90dd30efa2d2d6612a6882a2baa/packages/ttypescript/src/patchCreateProgram.ts#L82 . The emit method has the following declaration: https://github.com/microsoft/TypeScript/blob/bfc55b5762443c37ecdef08a3b5a4e057b4d1e85/src/compiler/builderPublic.ts#L101 . The declaration specifies 5 arguments, but it's not true. Sometimes the emit method takes 6 arguments. And it's the reason for the error "Expression produces a union type that is too complex to represent".

It's hard to reproduce, but I created a branch in my other project to demonstrate the issue.

Steps to reproduce

  1. git clone https://github.com/mdmitry01/nestjs-boilerplate.git
  2. cd nestjs-boilerplate
  3. git checkout ttypescript-bug-demo
  4. npm i
  5. npm run demo

You should now see output like this:

argument true
argument true
argument undefined
argument undefined

I added a console.log to node_modules/ttypescript/lib/patchCreateProgram.js (this file modification is applied automatically by patch-package). Please open the node_modules/ttypescript/lib/patchCreateProgram.js file and look at the line 67. As you can see, I added one more argument to the newEmit function.

My environment

  1. Ubuntu 20.04
  2. Node v14.13.0
patroza commented 2 years ago

Any word on getting this merged?

patroza commented 2 years ago

thanks!