2.3.3 • Published 6 years ago

dts-element v2.3.3

Weekly downloads
83
License
MIT
Repository
github
Last release
6 years ago

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
2.3.3

6 years ago

2.3.2

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago