TypeScript:检查字符串数组是否包含字符串

时间:2020-03-25 12:16:29

标签: typescript

我想知道使用includes

在字符串数组中是否存在字符串
  const haveTicketAlready = () => {
    const parts = state.selectedEvent.eventParticipants;
    return parts.includes(state.id);
  }

其中 parts = ["recTFqe7g6Mr87QmG", "recCpqbezylDb6P0O"]state.id = "recCpqbezylDb6P0O"

给出错误Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345)

state具有界面

    state: {
        id: string;
        authState: boolean;
        uid: string;
        displayName: string;
        photoURL: string;
        selectedEvent: {
            title: string;
            description: string;
            cost: string;
            eventParticipants: [];
        };
    }

0 个答案:

没有答案
相关问题