简体   繁体   中英

What does 'void' in typescript mean?

So I came across online, and I am wondering what does void imply in Typescript?

Just like here:

private _handleProjectQuerySuccess(data: IProject[]): void  
{
    data.sort(this._projectSort);

    var pathname = this._$location.path();

    var activeSet = false;
    data.forEach((project: IProject) =>
    {
        project.active = pathname == '/' + project.id;
        activeSet      = activeSet || project.active;

        project.name        = this._$sanitize(project.name);
        project.description = this._$sanitize(project.description);
        project.url         = this._$sce.trustAsUrl(project.url);
        project.readme      = this._$sce.trustAsHtml(project.readme);

        project.title = project.name + (project.fork ? ' (fork)' : ' (repo)');

        this._scope.projects.push(project);

        this._projectMap[project.id] = this._scope.projects[this._scope.projects.length - 1];
    });

    if (!activeSet)
    {
        data[0].active = true;
    }
}

After we declared private, we implied void ... What does that mean?

This is just a type, as documented here:

Void

Perhaps the opposite in some ways to 'any' is 'void', the absence of having any type at all. You may commonly see this as the return type of functions that do not return a value:

function warnUser(): void {
    alert("This is my warning message");
}

Important to note that void and any types overlap a bit, which may be weird at first. While void may return no data (only null and undefined) - any may return any kind of data (including null and undefined).

当我们通过编译器显示没有错误时,基本上使用 void 然后我们在 void 的帮助下使用 void 我们使 undefine 通过浏览器和 Null 。

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