I have successfully implemented a method to export types defined in a declaration file for use within my project and for exporting to external projects.
The strategy that worked for me was wrapping the type in a namespace.
Project X on Github
@types/index.d.ts
declare namespace projectGlobal {
interface Person = {
name: string;
age: number;
}
}
// additional local types here, but unable to export...
interface Local {
func: () => string
}
src/index.ts
export type Person = ProjectGlobal.Person; // Exporting is only successful when referenced through namespace.
// export type Local = Local; // Unable to export successfully
const person1: Person = {
name: 'john',
age: 45
}
Project Y on Github
import {Person} from 'projectx';
const person1: Person = {
name: 'john',
age: 45
}
Although satisfied with this solution, I am curious to learn if there is a preferred best practice for achieving this.