1

I have a package where the src with the following structure:

┌────────┐     ┌───────┐   
│moduleA │─┬── │code.ts│   
└────────┘ │   └───────┘   
           │   ┌──────────┐
           ├── │code.d.ts │
           │   └──────────┘
           │   ┌──────────┐
           └── │types.d.ts│
               └──────────┘

where the code.d.ts has the definitions of the exports of code.ts and types.d.ts hold a namespacefor the types used in code.d.ts. This works well in the package but when I export it the namespace is not recognized in the code.d.ts file anymore. Also every article about how to export types is quite confusing. Can someone point me into a direction where to start figuring this out.

code.ts

export default class MyClass {
    createSubject(id: string): Promise<MyNamespace.Subject> {
        return this.put(`/subjects/${id}`)
    }

code.d.ts

export default class MyClass {
    createSubject(id: string): Promise<MyNamespace.Subject>

type.d.ts

declare namespace MyNamespace { 
  export interface Subject {
   id: String
  }
}

The code is auto generated from openAPI files, so type.d.ts just represent the types from the openAPI file and code.ts is a simple class with a method for every existing endpoint.

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
  • A code sample would clarify your issue at-hand a bit better. My guess is 1) `code.ts` takes priority over `code.d.ts` (rename one of those), 2) `d.ts` files are only seen as compilation input and not emitted (see [here](https://stackoverflow.com/questions/56018167/typescript-does-not-copy-d-ts-files-to-build/56440335#56440335) for a related answer) – ford04 Jan 31 '20 at 09:45
  • @ford04 added some code hopefully its more clear now – Andreas Köberle Jan 31 '20 at 13:52

0 Answers0