cevek / ttypescript

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

Move typescript to peer dependency? #22

Closed dsherret closed 6 years ago

dsherret commented 6 years ago

Hey, when having a typescript dependency of ^3.0.1 and installing the packages with yarn, it will create a node_modules/ttypescript/node_modules/typescript package with a < 3.0 version. This will cause all the source files to be parsed with TS 2.9, which lead to a lot of confusion for me hah. It's a problem because the SyntaxKind numbers have changed so the following happens:

function visitSourceFile(sourceFile, context) {
    console.log(ts.version); // 3.0.1
    console.log(ts.SyntaxKind[sourceFile.kind]); // PropertyAssignment, sourceFile was created with 2.9
    // etc...
}

I found that replacing the node_modules/ttypescript/node_modules/typescript folder with a 3.0 version or installing via npm solves the issue.

To fix this, would it be possible to change typescript to be a peer dependency? Or is there a better solution?

cevek commented 6 years ago

I think this problem happens because of typescript dependency >=2.7.0 Because if you install dev version of typescript this version matching doesn't work for him and ttypescript will install own typescript version. So if you install later another version of typescript, the installed typescript in ttypescript won't be deleted. But if you install it like yarn add ttypescript@latest typescript@latest it works nicely.

Actually I really don't understand why it have installed 2.9 in your case. It's nonsense

So I've just change typescript dependency to *

About peer dependency - npm doesn't install it automatically, just throw a warning about it.

Probably fixed in ttypescript@1.5.3

cevek commented 6 years ago

So, * doesn't help I've removed typescript dependency at all Fixed in ttypescript@1.5.4

dsherret commented 6 years ago

Awesome, I think that's the easiest solution. That's what I ended up doing in ts-nameof as well.

I'm pretty confident this will fix the problem so I'm going to close this issue. Thanks a lot for the fast fix!

Edit: Yup, just tried it and it works.