3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

react開発中にParsing error: Unexpected token, expected ";"

Posted at

何をしたかったか

react typescriptで開発中
ログインユーザーの情報をcontext内に保持する処理を書いてた
createContextの引数{}にtypeをアサーションしたかった

コード

export type LoginUserContextType = {
    loginUser: User | null;
    setLoginUser: Dispatch<SetStateAction<User | null>>;
};

export const LoginUserContext = createContext<LoginUserContextType>({} as LoginUserContextType);

エラー文原文

Failed to compile
src/providers/LoginUserProvider.tsx
  Line 10:72:  Parsing error: Unexpected token, expected ","

   8 | };
   9 |
> 10 | export const LoginUserContext = createContext<LoginUserContextType>({} as LoginUserContextType);
     |                                                                        ^
  11 |

エラー文訳(Deep L翻訳)

構文解析エラーです。予期しないトークン、期待される ","

原因

何かしらのルールで許可されていない

改善案

.eslintrc.ymlに下記を追加

extends: [
  'react-app',
  'react-app/jest'
]

参考文献

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?