何をしたかったか
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'
]
参考文献