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.

Error: unknown type: "TSJSDocNullableType"

See original GitHub issue

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)

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
ikatyangcommented, Nov 2, 2018

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

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

3reactions
jonnyarnoldcommented, Nov 2, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prettier 2.0 “2020”
Prettier has been trying not to corrupt these JSDoc type assertions ... 1.19 Error: unknown type: "TSJSDocNullableType" // Prettier 2.0 ...
Read more >
The unknown Type in TypeScript
TypeScript 3.0 introduced a new unknown type which is the type-safe counterpart of the any type.
Read more >
pretter下载之后使用报错了 - DCloud问答
... 10:59:34.916 throw new Error("unknown type: " + JSON.stringify(n.type)); ... [Format] 10:59:34.916 Error: unknown type: "TSJSDocNullableType" [Format] ...
Read more >
The unknown type in TypeScript
Anything is assignable to unknown , but unknown is not assignable to anything but itself and any without a type assertion or a...
Read more >
What is the "unknown" Type in TypeScript?
In TypeScript, any value can be assigned to the "unknown" type, but without a ... const val6: Record<string, any> = val; // Will...
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