next.js with typescript fails with unexpected token `?`

Viewed 303

next.js npm run dev keeps failing with this optional property in tsx file:

Syntax error: Unexpected token

  44 |
  45 | type State<T_HT> = {
> 46 |   ghostHighlight: ?{
     |                   ^
  47 |     position: T_ScaledPosition
  48 |   },
  49 |   isCollapsed: boolean,

what causes this, how to resolve this

2 Answers

Optional properties, question mark should come before colon as below

ghostHighlight ?: {
  position: T_ScaledPosition
}

Question mark position is wrong here. The question mark should be like this

      45 | type State<T_HT> = {
    > 46 |   ghostHighlight?: {
      47 |     position: T_ScaledPosition
      48 |   },
      49 |   isCollapsed: boolean,
Related