Ts-loader: TypeScript 3.7-RC doesn't work

Created on 26 Oct 2019  Ā·  13Comments  Ā·  Source: TypeStrong/ts-loader

Expected Behaviour

Transpiles optional chaining just like tsc do

a?.b?.c // works in tsc, but fails in ts-loader

Actual Behaviour

Getting an error "You may need an additional loader to handle the result of these loaders."

Steps to Reproduce the Problem

  1. Use optional chaining in you project
  2. Start webpack

Most helpful comment

I think I've spotted the next Y2K bug in that enum šŸ˜‰

"We've only got 92 years of TypeScript left!"

All 13 comments

ts-loader uses whatever comes out of tsc - I'd be surprised if tsc isn't supporting optional chaining via the APIs.... šŸ¤”

cc @andrewbranch @sheetalkamat does this ring any bells?

What is target set to in your tsconfig?

What is target set to in your tsconfig?

My target is esnext, should I change it on somthing different?

Well, I've changed target to es2018 and it works just fine! Thank you!

Can anybody explain what the difference between targets: esnext and es2020 if at this moment it's the same?

esnext is a moving target. In the year 2030, es2020 will be old hat but esnext will always contain the latest and greatest features yet to make it into the ECMAScript spec, like perhaps syntax primitives for quantum computing operations, or my upcoming ā€œincredulous chainingā€ operator proposal, what‽.in‽.the‽.world‽.is‽.that.

In other words, esnext is always an alias to the latest spec version, and we continue to move it forward every year.

@andrewbranch ok, just as I suspected. But how this affects to ts-loader? I mean why target esnext is causing an error
image
but target es2020 not because esnext are equivalent of es2020 at current moment?

UPD: or it is not ts-loader error?

Sorry, I actually misremembered this. esnext and latest are aliases for each other, but es2020 is actually already a set value:

image

I think I've spotted the next Y2K bug in that enum šŸ˜‰

"We've only got 92 years of TypeScript left!"

Well fortunately TypeScript enums support non-integer number values, although I’m definitely going to spend the next 92 years looking forward to when we have to do safe floating point comparisons throughout the compiler whenever we look at target šŸ˜‰

I think somebody should make an issue in Typescript repo to prevent this bug šŸ˜€

So is it possible use ts-loader with esnext?

ts-loader has no problem with esnext. The problem you’re seeing is that Webpack itself can’t statically analyze the output JavaScript because _it_ doesn’t understand ?. and ?? yet. This is a good thing, because _browsers_ also do not understand ?. and ?? yet, so Webpack is saving you from shipping unsupported code to your users.

Oh, thank you Andrew!

Was this page helpful?
0 / 5 - 0 ratings