Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript tsc > redirection of messages

Tags:

typescript

tsc

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.

like image 499
user1747344 Avatar asked Oct 15 '12 14:10

user1747344


2 Answers

The > operator only redirects stdout. Errors are written to stderr. To also redirect stderr, append 2>&1 to the command. Backgrounder info is here.

like image 133
Hans Passant Avatar answered Oct 23 '22 10:10

Hans Passant


Try use:

tsc greeter.ts > err.log 2>&1

this worked good to me.

like image 2
Diullei Avatar answered Oct 23 '22 10:10

Diullei