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

TypeScript 3.7 Support #903

Closed
lukeshiru opened this issue Nov 7, 2019 · 9 comments

Comments

@lukeshiru
Copy link

@lukeshiru lukeshiru commented Nov 7, 2019

I have TypeScript 3.7 installed on a project, and I run tests with ava and ts-node. The issue I found is that compilation works as expected, but tests fail because ts-node doesn't recognize the syntax for nullish coalescence and optional chaining.

So if I have:

foobar?.foo?.bar ?? "default value"

I get errors all over the place. Isn't ts-node using the local typescript package to do compilation?

@keesvanlierop

This comment has been minimized.

Copy link

@keesvanlierop keesvanlierop commented Nov 7, 2019

It does, but it is set to 3.6.4 still. Needs to be updated and then good to go I think?

@blakeembrey

This comment has been minimized.

Copy link
Member

@blakeembrey blakeembrey commented Nov 7, 2019

TypeScript 3.7 is already supported, you would need to update your local installation.

@blakeembrey blakeembrey closed this Nov 7, 2019
@keesvanlierop

This comment has been minimized.

Copy link

@keesvanlierop keesvanlierop commented Nov 7, 2019

@blakeembrey It's not supported though. As OP mentions, you'll see errors on optional chaining and nullish coalescing expressions when running ts-node, even though your local typescript version is set to 3.7.2.

@lukeshiru

This comment has been minimized.

Copy link
Author

@lukeshiru lukeshiru commented Nov 7, 2019

One of the errors I'm getting:

Uncaught exception in src/tryCatch/tryCatch.test.ts

  ./node_modules/ts-node/src/index.ts:493

  ./src/tryCatch/tryCatch.ts:16
          returnedValue = catchCallback?.(error);
                                        ^

  SyntaxError: Unexpected token '.'

  Module.m._compile (node_modules/ts-node/src/index.ts:493:23)
  module.exports (node_modules/default-require-extensions/js.js:7:9)
  require.extensions.<computed> (node_modules/ts-node/src/index.ts:496:12)

Tried a clean install with npm, still getting errors.

@keesvanlierop

This comment has been minimized.

Copy link

@keesvanlierop keesvanlierop commented Nov 7, 2019

I noticed the fix is to change "target": "esnext" to "target": "es2018" in your tsconfig. No change required here.

@blakeembrey

This comment has been minimized.

Copy link
Member

@blakeembrey blakeembrey commented Nov 7, 2019

By that error it is compiling correctly. The error is a node.js runtime error, not TypeScript compilation. As noted it’s failing because you’re compiling an output that node.js doesn’t understand yet.

@lukeshiru

This comment has been minimized.

Copy link
Author

@lukeshiru lukeshiru commented Nov 7, 2019

Ohhhh yup. It seems to be a target issue. Thanks @keesvanlierop 😄

@iwasaki-kenta

This comment has been minimized.

Copy link

@iwasaki-kenta iwasaki-kenta commented Nov 15, 2019

Is there any way to have nullish coalescing work on target esnext? The use case is that bigint's are only supported should esnext be targeted, rather than es2018.

@lukeshiru

This comment has been minimized.

Copy link
Author

@lukeshiru lukeshiru commented Nov 15, 2019

@iwasaki-kenta my solution was to set target to es2018 and then:

"lib": [
      "es2018",
      "esnext.bigint"
    ]

So I have 2018 stuff, but I still support BigInt. It will only work expressed as BigInt("1") not like 1n 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.