简体   繁体   English

console.log()'ing 类型“any”变量会导致 Typescript 上的错误吗?

[英]Will console.log()'ing type “any” variable cause error on Typescript?

I will console.log(variable: any) in Typescript, but I don't want it to cause an error, and I don't want to add try{}catch block everywhere.我会在 Typescript 中使用 console.log(variable: any),但我不希望它导致错误,也不想到处添加 try{}catch 块。 Will console.log(any) cause any type of error? console.log(any) 会导致任何类型的错误吗? Or will it print everything I give?还是会打印我给的所有东西?

public print(data:any){
    console.log(data);
}

No, it will not.不,它不会。 Typescript is used to statically analyze code. Typescript 用于静态分析代码。

MDN words about console log ( https://developer.mozilla.org/en-US/docs/Web/API/Console/log ): MDN 关于控制台日志的话( https://developer.mozilla.org/en-US/docs/Web/API/Console/log ):

The Console method log() outputs a message to the web console. Console 方法 log() 将消息输出到 web 控制台。 The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.该消息可以是单个字符串(具有可选的替换值),也可以是任何一个或多个 JavaScript 对象。

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

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