I have a code with the following structure:
export class Component { constructor(options: Component.Options) {} } export namespace Component { export interface Options { // some values here... } } Then it is used like this:
import {Component} from './component' const options: Component.Options = {}; new Component(options); The issue happens, when Options definition is growing too much and we would like to extract namespace with interfaces into a separate file:
./component/interfaces.ts
export namespace Component { export interface Options { // some values here... } } ./component/index.ts
export * from './interfaces'; export class Component { constructor(options: Component.Options) {} } When this separation happens, the code becomes not valid, Typescript returns an error
index.ts:3:16 - error TS2702: 'Component' only refers to a type, but is being used as a namespace here. const options: Component.Options = {}; ~~~~~~~~~ Is there a way to fix it without changing the exported names? We cannot do this, because these interfaces are already consumed by customers and we cannot change the names within a minor version bump.