Bug fix for "Expression produces a union type that is too complex to represent" error #112
+11
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! I use
ttypescript
package in a private project. When I compile the project usingtsc
, I have no compilation errors. But when I usettsc
(note the doublet
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
replacesemit
methodttypescript/packages/ttypescript/src/patchCreateProgram.ts
Line 82 in 505e3aa
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
git clone https://github.com/mdmitry01/nestjs-boilerplate.git
cd nestjs-boilerplate
git checkout ttypescript-bug-demo
npm i
npm run demo
You should now see output like this:
I added a
console.log
tonode_modules/ttypescript/lib/patchCreateProgram.js
(this file modification is applied automatically by patch-package). Please open thenode_modules/ttypescript/lib/patchCreateProgram.js
file and look at the line67
. As you can see, I added one more argument to thenewEmit
function.My environment