I’ve just installed TypeScript as a Node.js package, and to my surprise it seems to be working straight away. But I cannot find a way of intercepting any messages it might generate. Doing the following with a greeter.ts file that has an intentional error
tsc greeter.ts > err.log
confirms that no redirection is occurring. Anyone know a way round this? I want to do this so I can pick up errors in my editor.
By the way, I’ve noticed that tsc only accepts lowercase file names. Doing tsc GREETER.TS gives Error reading file "GREETER.TS": File not found.
In response to Sohnee’s comment: No, tsc is definitely issuing an error message, it’s just that I cannot redirect it. My greeter.ts file, complete with intentional error is:
function greeter(person) {
return "Hello, " + person;
}
var user = "Jane User";
undeclared
document.body.innerHTML = greeter(user);
From an OS shell I get the following.
C:\K_F90\F90WX\BOOKS\THENOD~1>tsc greeter.ts
C:/K_F90/F90WX/BOOKS/THENOD~1/greeter.ts(7,0): The name 'undeclared' does not exist in the current scope
But when I try to redirect I get:
C:\K_F90\F90WX\BOOKS\THENOD~1>tsc greeter.ts > err.log
C:/K_F90/F90WX/BOOKS/THENOD~1/greeter.ts(7,0): The name 'undeclared' does not exist in the current scope
C:\K_F90\F90WX\BOOKS\THENOD~1>type err.log
C:\K_F90\F90WX\BOOKS\THENOD~1>
Pretty conclusive I think; an error message is being issued but is not being redirected to err.log, which is empty.
The >
operator only redirects stdout. Errors are written to stderr. To also redirect stderr, append 2>&1
to the command. Backgrounder info is here.
Try use:
tsc greeter.ts > err.log 2>&1
this worked good to me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With