JSPM

  • Created
  • Published
  • Downloads 13097
  • Score
    100M100P100Q131923F
  • License Apache-2.0

DOM for TypeScript Declaration Files

Package Exports

  • dts-dom

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dts-dom) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm version

dts-dom is a library for programatically generating TypeScript declaration files. It is based mostly on the same CodeDOM provided for C# and other .NET languages.

dts-dom automatically handles indentation, formatting, and proper placement of declare and export keywords.

As with other CodeDOM libraries, this is overkill for small projects, but is useful in more complex code generation scenarios.

PRs gladly accepted as this is mostly implemented on an as-needed basis for another project.

Usage

npm install --save dts-dom

import * as dom from 'dts-dom';

const intf = dom.create.interface('MyInterface');
intf.jsDocComment = 'This is my nice interface';
intf.members.push(dom.create.method(
    'getThing',
    [dom.create.parameter('x', dom.type.number)],
    dom.type.void,
    dom.MemberFlags.Optional));

const ns = dom.create.namespace('SomeNamespace');
ns.members.push(intf);

console.log(dom.emit(ns));

This writes out the block:

declare namespace SomeNamespace {
    /**
     * This is my nice interface
     */
    interface MyInterface {
        getThing?(x: number): void;
    }
}