Skip to content

Issues exporting a single d.ts for our code base #4315

@Davidhanson90

Description

@Davidhanson90

So we have built a large library which is structured as follows

src
---------- >Foo
----------> Bar
----------> Baz

Foo folder contains many ts files and at the root of each folder is a index.ts Folders like foo may also have sub folders with their own index.ts files in them. We compile all this by doing a tsc compile to produce a single js file.

tsc src/index.ts --out app.js. 

This all works well in our current app because all the type information flows through and we are using namespaces to group functionality. Example App.Framework.Foo.Bar.

Now we have new projects being kicked off by other teams who would like to use our library. Ideally we wanted to given them the single JS file to import into the app and a single d.ts file they they can use for the type annotations. However we have run into an issue generating the d.ts.

We updated our compilation step to use the --declaration flag and it does generate a single d.ts file with what looks like all the types in it. However, this d.ts file cannot currently be used by other teams due to the following.

The d.ts file has an type specified like this

declare module Foo.Bar {
    class Baz extends Implements Quax{
        constructor(message: string, source?: any);
    }
}

and then at the top of the d.ts file is a reference to some other d.ts file which has type info for Quax

/// <reference path="foo/bar/contracts.d.ts" />

Now the problem occurs due to the fact that inside that contracts.d.ts file it has additional refs to .ts files.

/// <reference path="enums.ts" />

So the two major issues I have here are that firstly I have to dist all d.ts files in the same tree structure in order for the single d.ts that was generated to be consumed by another team, but also the .ts file references would actually require me to dist the source too.

So I feel like I have run out of options. Creating these d.ts file manually would take a very long time and they would inevitable get out of sync so I am loathed to do that.

Hope people can provide some help,

Dave

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions