简体   繁体   中英

Parsing error: Unexpected token, expected “,” - React with Typescript

I'm getting this message error, this never happened before... I'm comparing to a code and it's exactly like that and it's not showing any error.

My Code:

interface AuthState {
  token: string;
  user: User;
}

interface SignInCredentials {
  login: string;
  senha: string;
}

interface User {
  id: number;
  name: string;
  login: string;
}

interface AuthContextData {
  user: User;
  token: string;
  signIn(credentials: SignInCredentials): Promise<void>;
  signOut(): void;
}

const AuthContext = createContext<AuthContextData>({} as AuthContextData);

const AuthProvider: React.FC = ({ children }) => {
  const [data, setData] = useState<AuthState>(() => {
    const token = localStorage.getItem('@Ponteflix:token');
    const user = localStorage.getItem('@Ponteflix:user');

    if (token && user) {
      return { token, user: JSON.parse(user) };
    }

    return {} as AuthState;
  });

Can soomeone help me?

Img:

在此处输入图像描述

To my knowledge, should the AuthContextData should be the return type?

const AuthContext = createContext<AuthContextData>(): AuthContextData;

This is a ESLint problem, I solved including eslintrc.json inside project root with it's configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM