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?
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.
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.
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."
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.
This is just a type, as documented here:
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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With