Giter Club home page Giter Club logo

dts-element's Introduction

dts-element

npm build coverage

A DOM library for generation TypeScript declaration (.d.ts) files

Changelog - Examples - Documentation

Features

  • reusable
    • FunctionDeclaration: it can be method or function based on where it is.
    • VariableDeclaration: it can be property or variable based on where it is.
  • parsable
    • parsing TypeScript syntax into dts-element using dts.parse(), useful for restructuring types

Installation

using npm

npm install --save dts-element

using yarn

yarn add dts-element

Usage

Code

import * as dts from 'dts-element';

const getThing = dts.create_function_declaration({
  name: 'getThing',
  type: dts.create_function_type({
    parameters: [
      dts.create_parameter_declaration({
        name: 'x',
        type: dts.number_type,
      }),
    ],
    return: dts.void_type,
  }),
}); // equivalent to dts.parse('function getThing(x: number): void;').members[0];

const MyInterface = dts.create_interface_declaration({
  name: 'MyInterface',
  jsdoc: 'This is my nice interface',
  type: dts.create_object_type({
    members: [
      dts.create_object_member({
        optional: true,
        owned: getThing,
      }),
    ],
  }),
});

const SomeNamespace = dts.create_namespace_declaration({
  name: 'SomeNamespace',
  members: [MyInterface],
});

console.log(dts.emit(
  dts.create_top_level_element({
    members: [SomeNamespace],
  }),
));

Output

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

Development

# test
yarn run test

# build
yarn run build

# lint
yarn run lint

# generate docs
yarn run docs

Related

  • dts-dom: another dts DOM library from TS team member

dts-element's People

Contributors

dependabot[bot] avatar greenkeeper[bot] avatar ikatyang avatar renovate-bot avatar renovate[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.