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] add support for optional chaining #6595

Closed
patrik-piskay opened this issue Oct 2, 2019 · 40 comments · Fixed by #6657
Closed

[TypeScript 3.7] add support for optional chaining #6595

patrik-piskay opened this issue Oct 2, 2019 · 40 comments · Fixed by #6657
Labels
lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency

Comments

@patrik-piskay
Copy link

Environments:

  • Prettier Version: 1.18.2
  • Running Prettier via: CLI

Steps to reproduce:
I was able to reproduce in the playground when using the typescript parser, which I guess it's the parser that ends up being used by prettier in typescript files? In my case its happening for both .ts and .tsx file extensions.

https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBDAdAIwPzrCAGhAgAcYBLaAZ2VFQCd6IB3ABQYRpVQDcJyAJoRCZ6qMAGs4MAMolx5KAHNkMegFc4RABYwAtgBsA6tvLwq8sHBmcz5HmYCeycFRpFFVOPRisxSvVRkADNUAy8iACsqAA8AITFJaRlUPTgAGUU4ELCIkGiYmUUlAzgARXUIeBzwrRB5ei96FxhHEjgqMHpyMmESbtgjQRhtZAAOAAYifogvIzESF36O7x5sogBHSvg-Ui40KgBaKDg4ATPhejgt8iu-VACgpFDaoi89clUNOqpi0oqqtlnrk6jBUJghgIRsgAExENSocgGYoAYQgekCLig0HWIHUXgAKuCuC8vABfMlAA

Expected behavior: does not throw "Expression expected" syntax error when using optional chaining in typescript files

Actual behavior: throw "Expression expected" syntax error when using optional chaining in typescript files

@sosukesuzuki
Copy link
Member

Thanks for creating the issue. It is still in dev, we have not support it yet as mentioned in #6574.

@sosukesuzuki sosukesuzuki added the lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) label Oct 2, 2019
@lppedd
Copy link

lppedd commented Oct 2, 2019

@sosukesuzuki but you mean dev for Prettier or for TypeScript?

@sosukesuzuki
Copy link
Member

@lppedd I meant dev for TypeScript. But, I think we should prepare for TS 3.7 👍

@lppedd
Copy link

lppedd commented Oct 2, 2019

@sosukesuzuki thanks! Here we are already using TS 3.7 beta.

@alexander-akait
Copy link
Member

I think we need update ts parser

@sosukesuzuki
Copy link
Member

sosukesuzuki commented Oct 2, 2019

@evilebottnawi I think so too. But, I'm worried that we can't update typescript-estree that because of the version of Node that Prettier supports...

@0rvar
Copy link

0rvar commented Oct 2, 2019

Could we use the babel parser instead? It already has support for Typescript when using the typescript preset

@alexander-akait
Copy link
Member

@0rvar #6400, should be shipped in 1.19

@lppedd
Copy link

lppedd commented Oct 2, 2019

@evilebottnawi so that means after merging that PR, potentially I could build Prettier and use the Babel parser with 3.7 (and thus keep formatting)?

@alexander-akait
Copy link
Member

@lppedd should be, but we still need add tests to avoid regression

@lppedd
Copy link

lppedd commented Oct 2, 2019

@evilebottnawi sure. It would be only a temporary solution to keep using Prettier.

@fisker
Copy link
Member

fisker commented Oct 3, 2019

Can typescript v3.7.0-beta https://www.npmjs.com/package/typescript/v/3.7.0-beta help?
As I tested yesterday when I do #6519 , it's safe to update to v3.7.0-beta

@alexander-akait
Copy link
Member

@fisker sometimes ts command do big changes on alpha or beta, better wait stable release

@fisker
Copy link
Member

fisker commented Oct 3, 2019

@evilebottnawi you're right, I'm going to test on 3.7.0-beta to prepare for 3.7 stable release

@lppedd
Copy link

lppedd commented Oct 9, 2019

So, as I need to format TS 3.7, I forked this repository and merged on master what was needed to use it. I've published a temporary NPM package at https://www.npmjs.com/package/prettier-next-lppedd, feel free to use it (it's based on https://github.com/lppedd/prettier/tree/feat/babel_ts), I will remove it as soon as 1.19 is out.
Just set "parser": "babel-ts",

Example configuration

"prettier": {
  "printWidth": 90,
  "singleQuote": true,
  "tabWidth": 2,
  "endOfLine": "lf",
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "options": {
        "parser": "babel-ts"
      }
    }
  ]
},

Remember to alias the command prettier-next-lppedd with prettier.

@fisker
Copy link
Member

fisker commented Oct 9, 2019

You should not publish a npm package cause you cant unpublish it after 24 hours , should install from your repo

@thorn0 thorn0 changed the title [TS] syntax error for optional chaining in typescript files [TypeScript 3.7] add support for optional chaining Oct 9, 2019
@jwulf
Copy link

jwulf commented Oct 11, 2019

Remember to alias the command prettier-next-lppedd with prettier

I do: npm i -D prettier@npm:prettier-next-lppedd @babel/core @babel/preset-typescript

And edit my .prettierrc to be:

{
  "singleQuote": true,
  "trailingComma": "all",
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "options": {
        "parser": "babel-ts"
      }
    }
  ]
}

Prettier outputs in VS Code: Couldn't resolve parser "babel-ts"

Update: Reloading the VS Code window fixes this.

@lppedd
Copy link

lppedd commented Oct 11, 2019

@jwulf yes, that happen because you're still using the standard Prettier.
When you install Prettier, a new runnable command is also created under node_modules/.bin.
The temporary package has the command prettier-next-lppedd in bash.
image
But lets not clutter this issue, if you still have problems hit me up on mail.

@bradzacher
Copy link

bradzacher commented Oct 14, 2019

FYI, we just landed and released typescript-eslint/typescript-eslint#1045 which adds support for optional chaining, nullish coalescing and assertion functions in typescript-estree.

@thorn0
Copy link
Member

thorn0 commented Oct 15, 2019

@bradzacher Unfortunately, Prettier has troubles with updating to the new version of typescript-estree because we still support Node 6 and aren't ready for a major release yet. Is bringing back the support for Node 6 probably something we can ask you of?

BTW, didn't you miss this 3.7 syntax addition?

@bradzacher
Copy link

bradzacher commented Oct 15, 2019

hmmm, I did miss it. It wasn't listed in the beta release post.
I've raised typescript-eslint/typescript-eslint#1086 to track it.


We still have full compat with node 6, we just don't explicitly test against it any more. We only dropped explicit support to keep sync with ESLint themselves, and because it was EOL in April. AFAIK there weren't any breaking changes between node 6 -> 8 that should effect our codebase / cause us to lose implicit support.
I guess we can add back explicit support if you'd like?

@thorn0
Copy link
Member

thorn0 commented Oct 15, 2019

I guess we can add back explicit support if you'd like?

It would be wonderful.

@thorn0
Copy link
Member

thorn0 commented Oct 16, 2019

@bradzacher chokidar, one of your dependencies, requires "node": ">= 8", so it looks like we're out of luck.

@bradzacher
Copy link

In the process of exploring the removal of that dep.
We added a feature in 2.4 to attempt to alleviate problems with IDE plugins when using the parser in full typecheck mode (which prettier doesn't use).
I've got some thinking to do on this feature, as it's pretty complex, and has caused some problems for some users. I'll get back to you soon.

@MLoughry
Copy link

@lydell Is there a stated plan for releasing a version with this change?

@lydell
Copy link
Member

lydell commented Oct 30, 2019

@MLoughry Yes! We’ve just finished all blocking items for the 1.19 milestone.

@capaj
Copy link

capaj commented Nov 5, 2019

@lydell typescript 3.7 just came out, please run the release
http://giphygifs.s3.amazonaws.com/media/CT5Ye7uVJLFtu/giphy.gif

@lydell
Copy link
Member

lydell commented Nov 5, 2019

I was going to a couple of hours ago but ran into problems. I'll try again tomorrow.

@emadow
Copy link

emadow commented Nov 6, 2019

I was going to a couple of hours ago but ran into problems. I'll try again tomorrow.

👏 👏 👏

@nodece
Copy link

nodece commented Nov 6, 2019

@lydell Thank your team for looking forward to this feature. typescript 3.7 is faster.

@ShanonJackson
Copy link

Please prettier team, i'm too excited to use the new features

@kripod
Copy link

kripod commented Nov 7, 2019

Maintainers are definitely trying their best to cut a release as soon as possible. Postponing is still better than rushing towards a pile of potential issues.

We all appreciate the hard work put into this project and wish the best to everyone involved!

@JCMais
Copy link

JCMais commented Nov 7, 2019

For the ones that cannot wait for the new release, you can just install prettier from the master branch yarn add --dev prettier/prettier#master

@yordis
Copy link

yordis commented Nov 7, 2019

No. Give me a release

P.S:

Thumbs-down voters: come on folks, don't make somebody feel shame (I would feel that way) because they are so happy to have such fantastic feature, do you realize how exciting this feature is?

They want to share with you 🤷🏻‍♂️ why not?! Be friendly and welcoming; it takes less energy and will make you feel better.

I get it, you get useless notifications (like mine), unsubscribe if that bothers you that much, the ticket is closed anyway. ☮️

@vernondegoede
Copy link

The goal of issues is to discuss the actual issue itself and/or stuff that has to be done around the issue, instead of creating a place to distract the maintainers from actually fixing the issue. @yordis

@yordis
Copy link

yordis commented Nov 7, 2019

@vernondegoede I agree with you, that is why you close the threads 😉

So you avoid toxic environments where some people want to focus on pragmatism but at the cost of people that don't understand that 🤷🏻‍♂️ I am just trying to help you.

Hard to disagree with your thoughts since I am more alike to you, but I refuse to justify toxic behaviors for such pity thing.

Close the thread as soon as things are resolved, the problem is solved.

@BrandonKowalski
Copy link

Not to beat a dead horse further but this is the ultimate irony @yordis ....

facebook/create-react-app#7438 (comment)

With that said thanks for the workaround @JCMais!

@yordis
Copy link

yordis commented Nov 7, 2019

@BrandonKowalski you are right thinking that way, but you are wrong thinking that people don't change and calling this irony, that is a simple conclusion.

Because of those exact words, I figured out what the solution for this issue is 😉

I figured out that being toxic helps nobody included the maintainers, so now I more proactive now.

Close threads if you want to stop these things from happening, otherwise stop being pitiful and toxic.

@alexander-akait
Copy link
Member

alexander-akait commented Nov 7, 2019

Locking for avoid toxicity, release will be tomorrow (Friday), big thanks for all who help us

@prettier prettier locked as too heated and limited conversation to collaborators Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency
Projects
None yet