TypeScript tsc> message forwarding

I just installed TypeScript as a Node.js package, and to my surprise, it seems to work right away. But I cannot find a way to intercept any messages that it can generate. Executing the following greeter.ts file with intentional error

tsc greeter.ts > err.log 

confirms that redirection does not occur. Does anyone know about this? I want to do this so that I can pick up the errors in my editor.

By the way, Ive noticed that tsc only accepts lowercase file names. Running tsc GREETER.TS gives the file with the error "GREETER.TS": file not found.

In response to Sohnees comment: No, tsc will certainly throw an error message, namely that I cannot redirect it. My intentional error greeter.ts file:

 function greeter(person) { return "Hello, " + person; } var user = "Jane User"; undeclared document.body.innerHTML = greeter(user); 

From the 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 convincing, I think; an error message is issued but is not redirected to err.log, which is empty.

+6
source share
2 answers

The > operator redirects only stdout. Errors are recorded in stderr. To also redirect stderr, add 2>&1 to the command. Information on the backgrounder is here .

+4
source

Try using:

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

It worked well for me.

+1
source

Source: https://habr.com/ru/post/927754/


All Articles