Is it possible to split the definition file index.d.ts into several files?

Viewed 1587

I am trying to write typescript definitions for an existing project that's written in ES6.

It exports an object with several classes, like:

export { default as Game } from './Game/Game';
export { default as Pool } from './Util/Pool';

Game is an ES6 class or object.

Rather than putting everything into a huge index.d.ts file with a big namespace, I'd like to have each class/object definition into its own file.

Can I do that ? how am I supposed to do that?

Right now, this is how my directory structure looks like:

// that's the JavaScript module I am using
node_modules/athenajs
// that's the new file I have created that will contain my typescript definitions
js/athenajs/@types/athenajs/index.d.ts
// that's the sample app I created to test my definitions
js/index.ts

Everything seems to be ok: when typing tsc -p . it correctly attempts to compile the file and correctly detects the index.d.ts file.

The question is: how can I split my definition into several .d.ts files, for example one for the definitions of the Game class, one for the Pool one, and so on, and import all into a global definition file?

1 Answers

The following should probably work for you:

  1. Add some separate files with type definitions, e.g. Game.d.ts
  2. In index.d.ts write references to the other files in the form of /// <reference path="./Game.d.ts" />
Related