prettier: Error: unknown type: "TSJSDocNullableType"

I’ve got this error using babel 7 and typescript files

Error: unknown type: "TSJSDocNullableType"
at printPathNoParens (node_modules/prettier/bin-prettier.js:21788:13)
[error]     at Object.genericPrint$1 [as print] (node_modules/prettier/bin-prettier.js:19544:28)
[error]     at genericPrint (node_modules/prettier/bin-prettier.js:10130:18)
[error]     at node_modules/prettier/bin-prettier.js:10076:16
[error]     at Object.printComments (node_modules/prettier/bin-prettier.js:9838:17)
[error]     at printGenerically (node_modules/prettier/bin-prettier.js:10075:22)
[error]     at node_modules/prettier/bin-prettier.js:23606:34
[error]     at FastPath.each (node_modules/prettier/bin-prettier.js:9977:7)
[error]     at printArrayItems (node_modules/prettier/bin-prettier.js:23604:11)
[error]     at printPathNoParens (node_modules/prettier/bin-prettier.js:21065:70)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 15 (9 by maintainers)

Most upvoted comments

@jonnyarnold @itrew TSOptionalType is supported since 1.14 (#4757), I guess you forgot to update?

(TSOptionalType -> string? in tuple, TSJSDocNullableType -> ?string)

Hello 😃 I stumbled upon this in my own investigation of this error, and can shed a little more light on this.

Typescript 3.0 brought with it optional tuple types, so I can declare a type like:

// An array with either 2 or 3 elements. (The `?` is the new bit!)
type PairOrTriple = [string, number, boolean?];

// Valid typings
const pair: PairOrTriple = ["foo", 1];
const triple: PairOrTriple = ["bar", 2, true];

It looks like prettier (and Typescript’s own compiler, before v3.0) considers the ? as JSDoc that should be in a comment. However, it’s now valid Typescript.

I don’t think we should handle it, just improve the error message in this case.

@ikatyang sounds good? I’ll try to come up with something good in a PR

@j-f1 That’s not valid in TypeScript and only valid in JSDoc.