Can't work around the Object Might be Null in Typescript [closed]

Discussão em 'Angular' iniciado por BostonMacOSX, Setembro 23, 2024.

  1. BostonMacOSX

    BostonMacOSX Guest

    Below is the code which is revealing that the object might be null however it is inside of a loop which wouldn't get executed if there are no members in the loop.... not sure why Typescript is saying there is a null error here...

    this.requestService
    .getAccounts(data.user.uid, token.access_token)
    .subscribe((res) => {
    var toloop = res.body;
    var needsupdate = "green";
    //GET THE INDIVIUAL INFORMATION ON AN ACCOUNT
    for (let i = 0; i < (toloop as Array<Object>).length; i++) {
    var toloopviewcolor = "green";
    if ("id" in toloop) { <<---this is possibly Null
    this.requestService.getRequest(toloop["id"]).subscribe( <<this is possibly Null
    (account) => {
    // Create "missing environments" array if addressses exist for display logic
    if (account["addresses"]) {

    Continue reading...

Compartilhe esta Página