Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dts-dom

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dts-dom

DOM for TypeScript Declaration Files

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-12.33%
Maintainers
2
Weekly downloads
 
Created
Source

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.DeclarationFlags.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;
    }
}

Version History

2.0 (not yet released)

  • New Functionality: Added the ability to emit triple-slash directives #39

    const tripleSlashDirectives = [create.tripleSlashReferenceTypesDirective("react")];
    const returnType = create.namedTypeReference('JSX.Element');
    const component = create.function('Component', [], returnType, DeclarationFlags.Export);
    const s = emit(component, { tripleSlashDirectives });
    

    The value of s is:

    /// <reference types="react" />
    export function Component(): JSX.Element;
    
  • Breaking Change: Changed the second parameter of emit from ContextFlags to EmitOptions #39

    // 1.0
    const s = emit(tree, ContextFlags.Module);
    // 2.0
    const s = emit(tree, { rootFlags: ContextFlags.Module });
    

1.0

The same as 0.1.25

Semver Policy

The major version will be bumped if:

  • The semantics of emitted code changes, even if the prior emit was categorically wrong
  • The API surface changes in a way that could break the runtime behavior of extant working code

The major version will not be bumped if:

  • New API surface is added
  • The formatting of emitted code changes

Contributors

The following people have contributed features and/or bug fixes. Thank you!

FAQs

Package last updated on 22 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc