The Typescript compiler APIs allow for programmatic creation of watch compilers through the use of the ts.createWatchCompilerHost API, with an example of it's use demonstrated in the Typescript docs here.
This API accepts a callback as its last argument that will be called anytime the watch status changes, with a Diagnostic object provided that describes the change in the watch status.
Using these diagnostic events, I'm attempting to discern between a compiling, success, and failure state. I've got detection of compiling state working fine, but I've come across an oddity when determining the difference between success and failure.
The trouble I'm having is due to the fact that the diagnostic codes are applied as follows. If there was 1 error while building, code 6193 is provided, otherwise code 6194 is provided. This means that code 6194 is provided if there were no errors (a success) or if there were 2+ errors (a failure). You can see this logic in the ts compiler here.
What is the expected way for a user of createWatchCompilerHost to determine between the case of no errors on build and the case of 1+ errors on build?
A hacky solution is to parse the diagnostic.messageText to check for Found 0 errors. but that seems extremely fragile and is a solution I would prefer to avoid.