Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 420
uksz Avatar asked Oct 31 '15 07:10

uksz


People also ask

When should I use void TypeScript?

TypeScript Data Type - Void Similar to languages like Java, void is used where there is no data. For example, if a function does not return any value then you can specify void as return type. There is no meaning to assign void to a variable, as only null or undefined is assignable to void.

Why do we use void in angular?

Reasons you might add : void : Improves clarity - other devs don't have to read the method body to see if it returns anything. Safer - if you e.g. move code from another function into this one that has a return expr; statement in it, TypeScript will flag this mistake.

What is void in a function?

When used as a function return type, the void keyword specifies that the function doesn't return a value. When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal."

What does a void return type mean?

A void return type simply means nothing is returned. System. out. println does not return anything as it simply prints out the string passed to it as a parameter.


1 Answers

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");
}
like image 101
Radim Köhler Avatar answered Oct 08 '22 18:10

Radim Köhler