question: why isn't it tslib distributed together with tsc?
It was a surprise for me I was using tslib indirectly, due to an dependency of another package. When I removed this package, the compilation ceased to build my solution and it took me some time to understand what was going on.
I would expect tslib to be installed together with tsc. On the case this separation makes sense, though, I think tsc could declare it as a peerDependencies, so this would be clearer.
tslib is a "reimplementation" of the helper functions used by TS. It is used if you do use the tsc option importHelpers. Or you use noEmitHelpers with manual adding this code.
In all other cases typescript compiler will not use the tslib code but add them on top of each js file when needed.
hey, @HolgerJeromin, you are obviously correct.
My point is that I only understood what was going on after re-reading the documentation for importHelpers. Unfortunately, the problem started after removing a package unrelated to tsc and it took me some time to find the error was being caused by this specific compiler option.
As Npm provides a standard way to ensure packages are present on runtime, using documentation to state "You will need to ensure that the tslib module is able to be imported at runtime" , instead, looks not the best idea to me. It declares what actually should be a dependency in a very fragile way.
Again, I'd expect all code related to TS-JS transpiling to be injected by tsc without implicit dependencies. We all use TypeScript to provide an automated way to describe and verify the correct way to use code; this wouldn't be necessary if we'd preferred to consult documentation ;)
@orta, if you'd think it is correct, please, tag this as a suggestion for improvement.
I think this is related to https://github.com/microsoft/TypeScript/issues/37991