简体   繁体   English

打字稿。 这是什么意思 :(<any> (() =&gt; 真))

[英]TypeScript. what does it mean :(<any>(() => true))

I am new to TypeScript.我是 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?这个任务的结果是什么?

()=> true is a short function form for regular function. ()=> true是正则函数的简写形式。 <any> is type casting, which tells typescript that the function can be any type and just ignore type errors. <any>是类型转换,它告诉打字稿该函数可以是任何类型并且忽略类型错误。 Outer most parentheses just scopes the whole expression for typecasting.最外面的括号只是范围用于类型转换的整个表达式。 The end result in javascript is as follows javascript中的最终结果如下

instance.nav.setRoot =  function(){
   return true;
}

The <any> a type casting. <any>类型转换。 It's making the compiler treat () => true as type any .它使编译器将() => true视为any类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM