Reputation: 33
I am new to TypeScript. Currently I am trying to understand some code related to testing and I came across this code,
instance.nav.setRoot = (<any>(() => true));
What is the meaning of the outermost parentheses? What is the result of this assignment?
Upvotes: 1
Views: 113
Reputation: 1621
()=> true
is a short function form for regular function. <any>
is type casting, which tells typescript that the function can be any type and just ignore type errors. Outer most parentheses just scopes the whole expression for typecasting. The end result in javascript is as follows
instance.nav.setRoot = function(){
return true;
}
Upvotes: 1
Reputation: 2480
The <any>
a type casting. It's making the compiler treat () => true
as type any
.
Upvotes: 0