-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
Add Encore.enableBabelTypeScriptPreset() to "compile" TypeScript with Babel #694
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the tested .ts
files don't actually contain anything that only works in Typescript. It wasn't a big deal for the previous test cases because we knew everything went through the TypeScript compiler anyway but maybe that should be added for this one?
I've added a small TypeScript-specific code, and tests pass fine. |
Wait a second :). If Babel is a better way to compile Typescript - I was just reading this article https://iamturns.com/typescript-babel/ - then why not make it a first-class citizen? Maybe we add a new:
And it takes care of everything for you:
WDYT? |
I don't know if it's a better way to compile TypeScript with Babel, but that's an interesting alternative. But note that you lose TypeScript power at compilation since every types are removed during transpilation. You need to run However, I will try to work on it tonight :) |
@weaverryan I've added support to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Kocal,
👍 for an enableBabelTypeScriptPreset()
method :)
Really minor comment + maybe a test should also be added in the test/config-generator.js
file? (similar to the one called "with configureBabelPresetEnv()")
Hi @Lyrkan, thanks for your review. |
This is really, really nice work. Thank you for an awesome new feature @Kocal! |
I ran into this trying to help someone on slack. #691 mentions to create a PR/issue for symfony-docs. Has said documentation ever been done? I could not find anything about it. |
I am guessing that's correct! |
See #691, I thought it can be interesting to have a test here.
Using Babel to "compile" TypeScript is faster than using
ts-loader
ortsc
directly, because in fact, it literally remove types annotations.To continue to check types, you have to run
tsc --emitDeclarationOnly
manually (or in a CI). But this is not part of the PR.To migrate an already existing TypeScript app, you just have to configure
babel-loader
to run over.tsx?
file like this:Install some dependencies:
yarn add --dev @babel/preset-typescript @babel/plugin-proposal-class-properties
.And modify your Babel configuration:
Maybe I can update
Encore.configureBabel()
and add an option to runs over TypeScript files too... like I did in #574, something like this:I've also changed the legacy import/export (
import a = require('...')
toimport a from '...'
). Because it's the legacy way (ES6 imports are very fine) and the Babel TypeScript was not compatible with them:EDIT : Added
Encore.enableBabelTypeScriptPreset()
that do all the job for us! :)Encore.enableBabelTypeScriptPreset()
can not be used asideEncore.enableTypeScriptLoader()
orEncore.enableForkedTypeScriptTypesChecking()
.