Currently, I am working on a repository that consists entirely of JavaScript code but also includes handwritten type declarations (automerge/index.d.ts).
The setup of the codebase includes a Frontend and a Backend, along with a public API that offers some additional convenience functions while re-exporting functions from both the Frontend and Backend.
An example structure is as follows:
declare module `foo` {
// Functions exclusive to the public API
function a
function b
function c
// Functions directly exposed from namespace A
function q
function r
function s
// Functions directly exposed from namespace B
function x
function y
function z
namespace A {
function q
function r
function s
function t
}
namespace B {
function v
function w
function x
function y
function z
}
}
The provided excerpt from the actual code highlights how we are repetitively declaring re-exported functions, leading to duplication.
declare module 'automerge' {
...
function getObjectById<T>(doc: Doc<T>, objectId: OpId): Doc<T>
namespace Frontend {
...
function getObjectById<T>(doc: Doc<T>, objectId: OpId): Doc<T>
}
...
}
I am seeking guidance on potential strategies to avoid redundant declaration writing in this context. Any insights or solutions would be greatly appreciated!