0
Why in Angular we use typing : void
? Example:
ngAfterViewInit(): void {}
0
Why in Angular we use typing : void
? Example:
ngAfterViewInit(): void {}
4
void
means something non-existent. It is not something specific to Angular but Typescript, actually even in the vast majority of static typing programming languages. By simplifying the languages only create functions, which presuppose that there will always be a result and it will be returned to the one who called (there is one or the other who preferred to separate and create procedures that have no return). So, what to do when the function does not return a value, not even a null value? It was agreed to use the void
indicating that nothing will be returned.
This occurs in functions that are not really functions, are procedures to be performed and only. Angular uses in several cases, you only have it executed and do not expect a result. What you would expect to receive in ngAfterViewInit()
? Nothing, he’s just initiating something, he did it, he ends it and he doesn’t return anything.
You cannot use these functions in expressions.
Browser other questions tagged angular function typescript typing
You are not signed in. Login or sign up in order to post.