question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optional chaining (?.) is not supported with "target": "esnext"

See original GitHub issue

Current behavior

It’s impossible to use optional chaining if "target": "esnext" is configured in tsconfig.json.

In fact, I would like to reopen the issue #9298.

In tsconfig.json:

"target": "esnext",

In spec:

cy.visit(objectWithUrlInside?.url);

Error:

Webpack Compilation Error
./cypress/integration/spec.ts 7:37
Module parse failed: Unexpected token (7:37)
File was processed with these loaders:
 * ../../../Users/mlegait/AppData/Local/Cypress/Cache/9.5.2/Cypress/resources/app/packages/server/node_modules/ts-loader/index.js
You may need an additional loader to handle the result of these loaders.
|             url: "https://example.cypress.io",
|         };
>         cy.visit(objectWithUrlInside?.url);
|     });
| });
GET /__cypress/tests?p=cypress%5Cintegration%5Cspec.ts 200 22.363 ms - -

Desired behavior

We should be able to use esnext as target with Cypress and have optional chaining supported.

Test code to reproduce

https://github.com/mlegait/cypress-test-tiny

Cypress Version

9.5.2

Other

No response

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:7
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
karlhorkycommented, Jul 1, 2022

@lmiller1990 @ZachJW34 any chance of supporting es2020, es2021, es2022, esnext and other newer values?

1reaction
karlhorkycommented, Aug 30, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

ts-jest Optional Chaining not working if tsConfig Target as ...
But Node JS doesn't support conditional chaining by default yet. So on using the ES2019 as the target, it transpiles and works on...
Read more >
Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
The optional chaining ( ?. ) operator accesses an object's property or calls a function. If the object accessed or function called is ......
Read more >
ts-jest Optional Chaining not working if tsConfig Target as ...
Coding example for the question ts-jest Optional Chaining not working if tsConfig Target as ESNext, ES2021 or ES2020-node.js.
Read more >
babel/plugin-transform-typescript
Note that although the TypeScript compiler tsc actively supports certain JavaScript proposals such as optional chaining ( ?. ), nullish coalescing ( ??...
Read more >
The Beauty of the Optional Chaining Operator (?.) in TypeScript
The optional chaining operator is supported all popular browsers except IE, Firefox for Android, Opera for Android and Samsung Browser.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found