For my project setup, I employ rollup to bundle an associated index.d.ts
(and index.js
) for the entrypoint src/index.ts
.
Within the project structure, there exists a directory named src/types
containing multiple .d.ts
files. These types are globally accessible in the project due to the inclusion of src/types
in the typeRoots
section of the tsconfig.json
file.
However, as the main entrance point to the project is index.ts
, these global types are not automatically exported to users of the npm module. To make them importable outside the project, all these types need to be redeclared and re-exported within the index.ts
file. Is there a way to include (///reference
) these type definitions from src/types
through the entrypoint index.ts
while still maintaining their convenient global accessibility within the project?
Here's an example:
// src/types/foo.d.ts
interface Foo {
bar: string;
}
// many more types...
// src/index.ts
export const HelloWorld = (input: Foo) => console.log("hello world", input.bar);
// tsconfig.json
{
...
"compilerOptions": {
...,
"declaration": true,
"typeRoots": ["src/types", "node_modules/@types"]
}
...
}
Consider this scenario where the project is being consumed:
import {HelloWorld, Foo} from "myModuleAbove";
const input: Foo = {bar: "hi"};
HelloWorld(input);
Is there a method similar to what is mentioned in this Stack Overflow post that can address this issue?
Thank you!