I am looking to enhance an existing TypeScript type within the global namespace in my library and then expose it for use in other projects. Can this be done?
Below is my current code:
Promise.ts
Promise.prototype.catchExtension = function<T>(this : Promise<T>): Promise<T> {
return Promise.prototype.catch.apply(this, [() => { /*do stuff*/ }]);
}
Promise.d.ts
declare global {
interface Promise<T> {
catchExtension(): Promise<T>;
}
}
export { }
How can I utilize this in another application that references my library? Since it was exported without a name using export { }
, I cannot use import { .... } from '@mylib'
.