Home > Mobile >  next.js with typescript fails with unexpected token `?`
next.js with typescript fails with unexpected token `?`

Time:09-28

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

CodePudding user response:

Optional properties, question mark should come before colon as below

ghostHighlight ?: {
  position: T_ScaledPosition
}

CodePudding user response:

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