Home > other >  Prettier supports for Optional chaining (?.)
Prettier supports for Optional chaining (?.)

Time:02-07

In my JavaScript React App I am using prettier for code formatting.

My current rules are working as expected. I saw that Prettier supports also Optional chaining, but when I run prettier --write that does not change for example user.info.name into user?.info?.name

Does someone have an idea what is the problem here?

Here is my .prettierrc:

module.exports = {
  trailingComma: "none",
  tabWidth: 2,
  semi: true,
  printWidth: 120,
  arrowParens: "avoid"
};

Version - "prettier": "2.1.2"

I am using Webstorm IDE

CodePudding user response:

Prettier doesn't make make changes that would alter the behavior of your code. Adding in optional chaining everywhere you access object properties would change the behavior, and isn't even desirable, so they don't do that. When prettier says they support optional chaining, they just mean that prettier can parse code that uses optional chaining, instead of throwing exceptions that the syntax isn't recognized.

  •  Tags:  
  • Related