简体   繁体   English

打字稿错误:类型{…}上不存在属性'log'-Console.log()

[英]typescript error: Property 'log' does not exist on type {…} - Console.log()

I have typescript files that are compiled into JavaScript files which ultimately run within a web application. 我将打字稿文件编译成JavaScript文件,这些文件最终将在Web应用程序中运行。 My ultimate aim is to have timers in these compiled JavaScript files so I can log how long it's taking for blocks of code to execute. 我的最终目的是在这些编译的JavaScript文件中添加计时器,以便我可以记录执行代码块所花费的时间。 In order to do this, I need to learn how to output data to a log file, and this (at its most basic) requires me to have some sort of Console.log('Whatever I want to log') statement in my JavaScript. 为了做到这一点,我需要学习如何将数据输出到日志文件,这(最基本的要求)要求我在JavaScript中具有某种Console.log('Whatever I want to log')语句。 。 I'm starting off small and then building off the baby steps. 我从小开始,然后建立起婴儿阶梯。

Since the typescript is compiled into JavaScript, I have to put any logging and timer code into the typescript first so that it will compile to JavaScript. 由于打字稿已编译为JavaScript,因此我必须首先将所有日志记录和计时器代码放入打字稿中,以便它将其编译为JavaScript。

I tried putting Console.log("...") into the typescript so that it would compile to the JavaScript and ultimately output "..." when the JS code was run. 我尝试将Console.log("...")放入打字稿中,以便将其编译为JavaScript,并在运行JS代码时最终输出“ ...”。 But during compiling, I got an error: 但是在编译期间,出现错误:

"Property 'log' does not exist on type '{ new (): Console; prototype: Console; }'"

  1. Why is this happening? 为什么会这样呢?
  2. What can I do to make sure that any "javascript code" that I have to first write in typescript gets compiled correctly? 我该怎么做才能确保我必须首先在打字稿中写的任何“ javascript代码”得到正确编译?

Obviously, I'm a complete newbie with any of this but my task remains nonetheless. 显然,我是其中的一个新手,但是我的任务仍然是。

Console.log("...") should be console.log("...") (lowercase c ). Console.log("...")应该是console.log("...") (小写c )。 This is TypeScript helping you preventing a mistake. 这是TypeScript可以帮助您防止错误。

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

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