简体   繁体   中英

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. 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. 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. 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.

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. 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?

Obviously, I'm a complete newbie with any of this but my task remains nonetheless.

Console.log("...") should be console.log("...") (lowercase c ). This is TypeScript helping you preventing a mistake.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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