'Issue with exporting from Typescript package

I'm writing a npm package which has a .d.ts file containing type declarations. The .d.ts file is generated during build. I also want to create a new file containing some enums and export it in the package as well. So here is the directory structure:

src/

  • stubs
    • index.d.ts
  • enums
    • index.ts index.ts

The stubs/index.d.ts file has the following code (which btw is generated code):

export interface IProduct {
}

export class Product {
  enum State {
    ACTIVE: 0,
    DELETED: 1,
  }
}

With the current state I'm not able to access the enum values for Enum state inside my application since enums are not supposed to be declared inside .d.ts files

So I'm creating a new .ts files which export const values corresponding for the enum. So for example in enums/index.ts I have

   import {Product} from '../src/';
 
   export const ProductState = {
    ...Product.State
   }

src/index.ts has

export * from './stubs';
export * from './enums';

So now in my application I expect to do something like

import {IProduct, ProductState} from 'mypackage';

I'm able to import IProduct but ProductState is still not accessible to my app. What can be the reason and how can I export the .d.ts file and .ts file as a single package so both are visible to my app ?

Here is my tsconfig

{
  "compilerOptions": {
    "resolveJsonModule": true,
    "target": "esnext",
    "module": "commonjs",
    "outDir": "./build",
    "strict": true,
    "moduleResolution": "node",
    "baseUrl": "./src",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false
  }
}

TIA.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source