Search code examples
reactjstypescriptvisual-studio-codeprettier

How to make prettier autoformatter in VScode not remove commas from typescript types after I added React


When I save a file with autoformatter on, the type

type Params = {
  fileName: string,
  isTxt: boolean
}

will be saved as

type Params = {
  fileName: string
  isTxt: boolean
}

Which React no longer accepts. Prettier only started deleting the commas after I added React to the project. How do I make prettier not do that?

I am using Prettier extension v9.0.0 and Typescript v4.5.2 in VScode 1.62.3.

Using .prettierrc

{
  "semi": false,
  "trailingComma": "none",
  "singleQuote": true,
  "printWidth": 80
}

Solution

  • You can set trailingComma to all