-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Feature Request: Typescript support #3
Comments
@devongovett If you had some time, can you please write the steps needed/files to be changed to enable TS support. Then I can try to do so too. Thanks 😉 |
Since parcel already has babel support, you can try using babel-preset-typescript , currently in beta. Register the |
Unfortunately It seems the ideal solution to this issue would be for Parcel to support TypeScript natively as an opinionated decision like fusebox does, or for someone to implement a TypeScript plugin that passes Personally I would prefer the former as I think it would be much cleaner to use and I feel the vast majority of the JavaScript community is already using TypeScript so this would be a desirable feature for a huge portion of your userbase. |
I think TypeScript support should totally be built in. We may require that you install I don't personally have any experience with typescript, so I'll need some input here. I like the idea of using
|
Yeah I agree, having it as a peer-dependency would be ideal so that the
Workflows for bundling a TypeScript project via Browserify, Webpack or FuseBox all utilize From what I can see the babel preset is basically just stripping all the TS stuff so you get plain JavaScript, going by this another potential solution could be to use the babel preset for transpiling, but call
|
Some suggestions. I think it would be ideal to send TypeScript errors/warnings to the browser console instead of to the local machine console. Really, TypeScript errors are just type check warnings, and it feels like a more unified experience to have all of my client code errors and warnings appear in one place, the browser console. It would also be ideal to not force the compilation to fail if there are any TypeScript errors, because again, they aren't really errors, the code will often still run, and for development it is sometimes nice to ignore TypeScript warnings to move quickly and prototype, going back to put in the types after things settle a bit. Allowing these two options would be ideal, and if you need help I've got som experience implementing this in a similar project. |
Worth noting is that Babel 7 will come with built in typescript support, so the problem might solve itself in the near future |
@wyqydsyq VSCode, Webstorm and probably other editors support TypeScript language service for code validation and type-checking errors directly inside the editor. This means you can have a nice Typescript developer experience while improving the compiler performance, because as you said, Babel does not do any type-checking. I remember I saw some tweets about using Babel instead of tsc to improve build time. I need to check my sources and find some benchmarks though. edit: here's the tweet I read https://twitter.com/jaredpalmer/status/936249988270706688 |
@GeeWee in planning for Babel 7
Wouldn't this bypass the type checking of tsc? |
I think we should do both:
There's no way to guarantee that Babel and TypeScript are perfectly in sync with syntax support. So people should have the option to stick to the TypeScript compiler. |
I'd suggest stating with Babel, and putting tsc on the backlog. |
In the interest of keeping the noise down on this issue, please use the 👍 button on the original post or any comments. |
@Olian04 yeah that's a good point, we'd want to fork and typecheck in a separate process, like e.g. ts-loader does, but in general not having the typechecker run 24/7 is not as big of a problem as one night think as the editors will autocomplete fine without. |
It’s worth keeping in mind that, even if you don’t care about type-checking, On top of that, Babel 7 still doesn’t support some Finally, Performance-wise, according to a Twitter thread linked here earlier, |
Also, in my experience the TypeScript compiler has been very nice to work with as an embedded library. |
Interestingly the first issue ever in TypeStrong's discussions repo is about normalizing non-standard |
Cool, sounds like we should go with the regular TypeScript compiler for compatibility by default. I think we can start with One unfortunate thing about this vs using babel is that it will probably require multiple parses/codegens, which I was trying to avoid for performance. We don't really want to reimplement all of the dependency analysis and other things that are currently implemented on top of the babel AST though. That means that TypeScript will parse and compile, and then babel will do the same. This isn't any worse that other bundlers currently, but a pure babel pipeline would avoid that. Anyway, here's how someone might go about doing this: You'll need to add a new Asset type. I'd inherit from Here's some pseudocode. const Asset = require('../Asset');
const localRequire = require('../utils/localRequire');
class TypescriptAsset extends JSAsset {
async parse(code) {
// require typescript, installed locally in the app
let typescript = localRequire('typescript', this.name);
// call typescript compiler
super(transpileModule(code));
}
} Would someone like to take this on? 😉 |
@d4rkr00t Maybe you want to take this on? 😉 |
I would love to, but seems like it's a little bit too late :) |
#84 has been merged and released in v1.1.0, which should cover the basics of transpiling. Closing this issue. If someone wants to open another one for typechecking support, feel free. |
EDIT: Ignore me, I was testing the wrong version. 1.1.0 is not in NPM yet. @devongovett I know this issue is already closed but I just found a bug. If the script index file has a My intuition is that the transpiled file should not have the |
TypeScript has neat and not-complex tsconfig.json for driving/tweaking compilation. Ideally that's supported automatically out of the box. TypeScript without That's what should be the baseline default expectation. |
@mihailik the tsconfig compiler options are used by the compiler, in this base implementation? |
On the versions: it would be FANTASTIC if parcel could build TypeScript out-of-the-box, without extra step of installing another package. But if a project wants to pick a specific version, that should be used instead. That sounds like a trivial setup: make |
Yes @DeMoorJasper , |
The reason local requires are used is because of package size and speed, lots of people don't need typescript to be installed so it's not required by Parcel but if they want to have it they just install the official typescript package and they have it without even touching any config file. |
You're getting me kinda confused about config files here, tsconfig files in parcel are loaded the same way we handle the babel config or any other config. @mihailik let tsconfig = await config.load(this.name, ['tsconfig.json']);
// Overwrite default if config is found
if (tsconfig) transpilerOptions.compilerOptions = tsconfig.compilerOptions;
transpilerOptions.compilerOptions.noEmit = false; |
@DeMoorJasper quite reasonable on the size. However TypeScript actualy only needs several files: |
For context: I've been following and contributing a few small bits to TypeScript since early, concerning compatibility and unusual integration scenarios. And totally agree with parcel's concerns in bundlers like webpack and browserify - so I'd love to help on TS integration, in whatever way fits with project's vision. |
@mihailik Feel free to open up a new RFC in issues with the idea's you have to improve Typescript support within parcel, i'm happy to help improve the typescript support in any way. |
@mihailik I'm not following your suggestion to use defaults. Are you suggesting that |
TypeScript support seems to work pretty fine already. EDIT: I ended up using https://github.com/ryanelian/ts-polyfill and applying the correct |
For me, TS compilation works fine, but for some reason, I can't see any errors/warnings from the compilation process. Does parcel intentionally swallow error messages? Is there any way to change that configuration? Thank you for explaining. |
@csillag i guess it's because |
Add pipeline steps for measuring warm build perf Approved-by: Will Binns-Smith <wbinnssmith@atlassian.com>
Skip AssetGraphBuilder test like upstream Approved-by: Maia Teegarden
No description provided.
The text was updated successfully, but these errors were encountered: