We're trying to work around an open issue in an open source library (let's call it openfoo) without having to fork it.
In our private library, we have a dependency on openfoo and a devDependency on @types/openfoo. Our library contains the file openfoo-patch.ts, which looks like this:
import * as openfoo from 'openfoo';
openfoo.Bar.prototype.etc = function () {}; // monkey patch
export * from 'openfoo';
In our other library modules (call one xyz) we do:
import { Bar } from '../openfoo-patch';
This guarantees that our patch runs before any other modules execute.
(Note that the second project is also a library, so there's no obvious way to say "run this at startup.")
Everything works fine, including unit/integration tests.
However, when we tried to build another library that has a dependency on our private library above, we get
node_modules/@ourcompany/ourfirstlibrary/build/xyz.d.ts:1:10 - error TS2305: Module '"../.../oursecondlibrary/node_modules/@ourcompany/ourfirstlibrary/build/openfoo-patch"' has no exported member 'Bar'.
1 import { Bar } from '../openfoo-patch';
We've tried moving @types/openfoo to a full dependency in the first library; that makes no difference. Installing @types/openfoo in the second library did not help either.
How can we get our second library to compile?
(Currently our first library uses TypeScript v3.6.4 and our second uses v3.8.2.)
Update
One workaround appears to be to remove the
export * from 'openfoo';
from the patch file, then change the other modules to
import '../openfoo-patch'; // ALWAYS import before openfoo
import { Bar } from 'openfoo';
This does require two imports, and it requires callers to remember to do this.