Solvedts node TypeScript 3.7 Support

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?

22 Answers

✔️Accepted Answer

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

Other Answers:

Also "target": "es2019" works for me but "target": "es2020" not yet.

@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.

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.

Related Issues:

303
ts node Custom typings not working with ts-node 8.0.2
When using with ts-node you have to add --files flag After updating to ts-node version 8.0.2 the cus...
163
ts node ts-node fails when ES Modules are in the dependency graph in Node.js 13+
It seems that ts-node fails to run with module: esnext in the tsconfig.json and type: module in the ...
121
ts node TypeScript 3.7 Support
I noticed the fix is to change target: esnext to target: es2018 in your tsconfig No change required ...
74
ts node Cannot find module 'typescript'
You'll need to install typescript locally since v8 it's using require.resolve which has its own sepa...
51
ts node "Unexpected token import" when dependency in .ts is an es6 module
In our case we're importing our own code (in our private repo Possibly related issue: #505 Setup Pro...
49
ts node Compilation is unbelievably slow
If anyone can give me temporary access to a slow repo let me know! I can quickly take a look into th...
32
ts node "Cannot find module 'http'. (2307)" with "@types/node" under typescript@2.0.3
I have the same problem TypeScript Version: 2.0.3 Code Expected behavior: should import http as well...
27
ts node Fail to load module from node_moules
Since I'm using Typescript for my project I also prefer Typescript modules as the dependencies ...
24
ts node VSCode Debugging
Just verified it working locally by creating a new project All I did is below Can someone confirm th...
23
ts node Type declaration merging doesn't work
Here is a working example for those who still struggling (like I was for past few hours): @types/exp...
22
ts node ts-node failing on "import" statements where tsconfig states "commonjs" module
ts-node doesn't compile dependencies in node_modules See https://github.com/TypeStrong/ts-node#confi...
20
ts node Worker Threads flag (node v10.5+)
If somebody wants to write thread workers as .ts files it's possible by having an intermediate .js f...
18
ts node Can't extend express Request type
To help anyone who is just looking for something else to try here is what worked for me when trying ...
17
ts node "error TS2304: Cannot find name" after updating to 7.0.0
Why make a major release so quickly? I do agree that as @weswigham says the build orchestrator is no...
17
ts node ts-node@7.0.0 ignore local type declaration files
@blakeembrey Got it .Thanks However Sometimes we need to declare module for packages without type de...
14
ts node Compilation error with mocha and TypeScript 2.0 on Windows 10
Giving types: [ node mocha chai ] under compilerOptions on tsconfig.json solve the issue. ...
3
ts node Using nyc (istanbul) with ts-node/register don't check coverage properly in versions from 3.3.0
@cibergarri Thanks for the response! I'll look into doing a release in the next week or two defaulti...
3831
axios Axios catch error returns javascript error not server response
I have exactly the same environment Try this: Modify from console.log(error) to console.log(error.re...
731
scrapy ' error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 '
@euler16 for scrapy with Python 3 you'll need with Python 2 you'll need I wanted to install scrapy i...
684
laradock Mysql. The server requested authentication method unknown to the client [caching_sha2_password]
alter user 'username'@'localhost' identified with mysql_native_password by 'password'; would fix it....
517
react navigation screenIsActive prop / componentDidFocus event for TabNavigator items
It probably makes sense to add lifecycle hooks to screens In one of my Tabs i need to load Data from...
474
meteor [1.4.2.1] Error: ENFILE: file table overflow
I was getting the same after an upgrade to macOS Sierra Turns out macOS have a harsh limit on number...
423
ipython Last jedi release (0.18.0) is incompatible with ipython (7.19 and 7.18 tested); reason - column arg was deprecated, and now removed
As a temporary fix for anyone just trying to get things working again: It would be really nice if yo...
397
material ui Module not found: Can't resolve 'material-ui-icons/Menu' Martial Next
For anyone else experiencing this issue: npm install @material-ui/icons https://www.npmjs.com/packag...
395
laravel dompdf (1/1) ErrorException Non-static method Barryvdh\DomPDF\PDF::loadView() should not be called statically
This happens because you are namespacing the wrong PDF class You are namespacing Barryvdh\DomPDF\PDF...
378
webpacker localIdentName option moved in css-loader configuration
I faced same issue after upading css-loader but I solved it If you check css-loader readme ...
364
react navigation Send data back from child screen?
@itswaze You can do something along these lines to pass back from the child screen ...
358
react navigation How to goBack from nested StackNavigator?
@dhruvparmar372 According to the NOTE in the doc a navigator's navigation prop may not have the help...
352
axios POST request works in Browser but not on Node
This might be considered a duplicate of #789 I was able to use the form-data package with Axios in n...
317
react navigation Best pattern for a 'Save' button in the header
Try setting your component instance's handleSave function as a navigation state parameter after the ...
310
DefinitelyTyped [@types/react] RefObject.current should no longer be readonly
It's not It'a intentionally left readonly to ensure correct usage even if it's not frozen ...
306
react native navigation [V3][Android] FATAL EXCEPTION: create_react_context
OK after a good night of sleep I've found why I was having this issue In the MainApplication.java I ...
294
ohmyzsh compinit:503: no such file or directory: /usr/local/share/zsh/site-functions/_brew
Per #9602 (comment) brew cleanup fixed it for me I am using Apple M1 When I added this line: export ...
292
laradock SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
+1 I'm having the same problem here. Info: Docker version ($ docker --version): Docker version 17.12...
289
vagrant vagrant box update - Fails with 404 Not Found error
A workarround to add in your Vagrantfile: Vagrant version Host operating system Ubuntu 16.04.3 LTS G...
263
vagrant vagrant --help displays a rubygems error
To fix this error: Vagrant version Host operating system Expected behavior vagrant and vagrant --hel...
262
date fns Can't resolve 'date-fns/_lib/format/longFormatters'
You probably forgot to install date-fns or Code: import DateFnsUtils from '@date-io/date-fns'; ...
259
virtualenv Error creating virtualenv with python3.6
The original poster's problem is due to not having the 'python3.6-venv' package installed ...
252
provider A Product was used after being disposed. flutter: Once you have called dispose() on a Product, it can no longer be used.
Oh I see what you're doing Don't: DO: i have a ChangeNotifireProvider that such that i do pushReplac...
248
react navigation Reset to nested route, "There is no route defined for..."
A quick workaround (not heavily tested): set the key property to null on your action. ...
238
axios Adding headers to axios.post method
Edit: I had to add Authorization to allowed headers in my CORS filter @jffernandez I'm having the sa...
231
axios Adding Retry Parameter
@mericsson I am too in need of exponential backoff when retrying I've put together the following whi...
224
homebrew openjdk Cask adoptopenjdk8 exists in multiple taps
I think AdoptOpenJDK8 should be removed from the homebrew-cask-versions repo Somone(TM) should proba...
222
nativescript cli TNS doctor doesn't recognize Xcode (High Sierra)
HI @philipfeldmann Can yhou please run xcodebuild -version and paste the output? May be Xcode is ins...
215
axios BaseURL not being used
Please IGNORE THIS ISSUE Found the problem: I was setting baseUrl but it should be baseURL. ...
205
axios How to ignore SSL issues
You can configure axios to use a custom agent and set rejectUnauthorized to false for that agent: Ho...
202
ipython NameError: name 'sys' is not defined
Ok that was easy The Jedi release on 12/25 version 0.18.0 is breaking tab completion pip install --u...
190
axios How to send Raw http for Instagram Authentication?
Yes StringClient uses the application/x-www-form-urlencoded format by default while axios uses appli...
186
vuetify [Bug Report] Could not find a declaration file for module 'vuetify/lib'
@KaelWD Thank you for the link More specifically this comment helped me out to properly update my ts...