如何正确注释对象以修复对象可能为“ null”

时间:2019-10-22 02:02:04

标签: reactjs typescript firebase

我收到以下错误:this.auth.currentUser上的对象可能为“ null”,如何正确注释此行以使错误消失?

方法:

doPasswordUpdate = (password: string): Promise<void> =>
    this.auth.currentUser.updatePassword(password)

注释: auth: firebase.auth.Auth

任何帮助都值得赞赏!

1 个答案:

答案 0 :(得分:2)

在这种情况下,您最好执行以下操作:

bool prior_line_ended = true;
while (1) {
    fgets(line, 75, fp);
    if (feof(fp)){
        break;
    }

    // Remove any line end:

    char* pos = strchr(line, '\n');
    //char* pos = strchr(line, '\r');
    //if (pos == NULL) {
    //    pos = strchr(line, '\n');
    //}
    bool line_ended = pos != NULL;
    if (line_ended) {
        *pos = '\0';
    }

    // Output when starting fresh line:

    if (prior_line_ended) {
        printf("%s\n", line);
    }
    prior_line_ended = line_ended;
}