Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[request] getCustomTransformer(program: ts.Program) just like as ts-loader's #792

Closed
gfx opened this issue Mar 3, 2019 · 4 comments · Fixed by #879
Closed

[request] getCustomTransformer(program: ts.Program) just like as ts-loader's #792

gfx opened this issue Mar 3, 2019 · 4 comments · Fixed by #879

Comments

@gfx
Copy link
Contributor

gfx commented Mar 3, 2019

In order to use a transformer that uses ts.Program / ts.TypeChecker, for example https://github.com/kimamula/ts-transformer-keys

See https://github.com/TypeStrong/ts-loader#getcustomtransformers--program-program---before-transformerfactory-after-transformerfactory-- for details.

It might be somewhat difficult because TypeScript compiler restricts the use of TypeChecker in transformers: microsoft/TypeScript#25147 , though.

@blakeembrey
Copy link
Member

@gfx You're welcome to submit a PR since I'm not 100% sure what you require here. I assume it won't work for ts.transpileModule though?

@gfx
Copy link
Contributor Author

gfx commented Mar 7, 2019

@blakeembrey

Thanks.

ts.transpileModule() does not provide ts.Program nor ts.TypeChecker instance, which is inevitable for compile-type type information.

BTW I've found https://github.com/cevek/ttypescript , a custom typescript compiler to provide ts.Program to transformers. It is also available as ts-node --typescript ttypescript and it works well for me.

I think the best way is that the official typescript compiler supports such transformers, and I have no idea what is the better 🤔

@saitonakamura
Copy link

I have a similar problem, I have a transformer that will generate runtime json validation based on generic type argument so I need an access to typeChecker in there.
https://github.com/ts-type-makeup/superstruct-ts-transformer
The way it's done with ts-loader, they create a program manually
https://github.com/TypeStrong/ts-loader/blob/35b1b5634eececa914f977c31ae182ed88f24987/src/instances.ts#L210

@saitonakamura
Copy link

@gfx nice find with ttsc! It would still be better the less hoops you need to jump, methinks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants