Argument of type 'Iaulasadicional[]' is not Assignable to Parameter of type 'string'

Asked

Viewed 482 times

2

Opa, I have this problem in my code which I am not able to solve, follows below my code I hope you can help me!!!

Stoned:

"AulasAdicionais": [
    {
      "Periodo": "1",
      "HorarioInicio": "2021-01-19T07:30:00-0300",
      "HorarioTermino": "2021-01-19T08:30:00-0300",
      "IdDisciplina": "396",
      "DescricaoDisciplina": "Matemática",
      "DescricaoReduzidaDisciplina": "Mat",
      "DescricaoTurno": "Manhã",
      "IdEstabelecimento": "43",
      "DescricaoEstabelecimento": "Colégio Correio Lima",
      "TipoSituacaoHorario": "Normal"
    }
  ]

My service

export interface IAulasAdicionais {
  Periodo: string;
  HorarioInicio: string;
  HorarioTermino: string;
  IdDisciplina: string;
  DescricaoDisciplina: string;
  DescricaoReduzidaDisciplina: string;
  DescricaoTurno: string;
  IdEstabelecimento: string;
  DescricaoEstabelecimento: string;
  TipoSituacaoHorario: string;
}

export interface IAgendaAulas {  
  AulasAdicionais: IAulasAdicionais[];

}

const getAgendaAulas = async (dataAula: string ) : Promise<IAgendaAulas[] | undefined> => {
  try {
    const { data } = await Api().get<IAgendaAulas[]>(
      `/agenda-aulas?DataAula=${dataAula}`
    );
    if (data) {
      return data;
    } else {
      return undefined;
    }
  } catch (error) {
    return undefined;
  }
};

This and my TSX:

interface IAgendasAulasProps {
  aulasAdicionais: IAulasAdicionais[];
}

export const AulasAdicionaisRecuperacao: React.FC<IAgendasAulasProps> = ({
  aulasAdicionais,
}) => {
  const classes = useStyles();
  const [aulaAdicionais, setAulasAdicionais] = useState<
    IAulasAdicionais[]
  >();

  useEffect(() => {
    AgendaTurmaService.getAgendaAulas(aulasAdicionais "O problema está aqui" ).then((data) => {
      if (data) {
        setAulasAdicionais(data "e aqui");
      } else {
        setAulasAdicionais([]);
      }
    });
  }, [aulasAdicionais]);

{aulaAdicionais?.map((horario, horarioIndex) => (
        <>
          <Grid container spacing={2} key={horarioIndex}>
            <Grid item lg={2}>
              <Box margin={1}>
                <Paper className={classes.root}>
                  <Box marginTop={2} marginLeft={1}>
                    <ClassIcon color="primary" style={{ fontSize: 90 }} />
                    <Box display="flex" marginTop={-10} marginLeft={12}>
                      <Typography>{horario?.DescricaoDisciplina}</Typography>
                    </Box>
                  </Box>
                </Paper>
              </Box>
            </Grid>
          </Grid>
        </>
      ))}

I will post a print of what is occurring to facilitate understanding Erro 1

Erro 2

  • Apparently the problem is where checked but it would be much more elucidative if it showed the code of these functions. Most likely the function getAgendaAulas returns an object with the property data which is an array of type IAgendaAulas, Then it’s passing that amount data for a function setAulasAdicionais receiving an array of type IAulasAdicionas as an argument.

  • Read code "online" in a comment?!? Please edit your question and add this code there (and by the way also the setAulasAdicionais).

  • Well sorry, but both are already in my question!

  • Ok. To set the additional lessons, try changing setAulasAdicionais(data); for setAulasAdicionais(data.AulasAdicionais);. As to the getAgendaAulas, I am not sure what the needs of the implementation are but I think there is some error in the definition of the function, because it expects the argument to be of the type string.

  • Thanks for your help, however when trying to access the date properties it n returns me nothing. There is another way for me to access these properties?

  • If you debug or even put a console.log after making the call to AgendaTurmaService.getAgendaAulas, what the content of data?

  • Return he does not return me anything! but was to contain the properties of Iaulasadicional

  • You will need to debugging to find the problem. Try checking if you are logging into catch. Also check that the API call is correct.

  • Debuggin in my debug console returns this to me

  • Please put a console.logon line 46 (before calling setAulasAdicionais) and then show the output.

  • I put the console.log(date) and the return and this

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.