Polymer/gen-typescript-declarations

Name: gen-typescript-declarations

Owner: polymer

Description: Generate TypeScript declarations from Polymer Analyzer output

Created: 2017-03-06 22:57:54.0

Updated: 2018-05-18 04:27:59.0

Pushed: 2018-05-21 22:06:11.0

Homepage: null

Size: 538

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

gen-typescript-declarations

Build Status NPM version

A library which generates TypeScript declarations for Polymer and custom elements.

How do I use the typings?
Polymer

Typings for Polymer 2 are planned for regular release starting with version 2.4, and are available in the types/ directory on the master branch now.

Once Polymer 2.4 is released, to use the typings, install Polymer normally from Bower, and add a triple-slash directive anywhere in your TypeScript project for the typings you require. Each HTML import from Polymer has a corresponding typings file. For example, if you depend on polymer-element.html:

<reference path="./bower_components/polymer/types/polymer-element.d.ts" />`

s MyElement extends Polymer.Element {
.

Alternatively, you can add the dependency to tsconfig.json in the root of your project:



"include": [
    "src/**/*.ts",
    "src/bower_components/polymer/**/*.d.ts",
]

Typings for Polymer 3 are planned but not yet available (see #18).

You may also be interested in the Polymer decorators.

How do I generate new typings?

You can run this package from the command line with gen-tsd, or as a library with the generateDeclarations function.

It is recommended to integrate typings generation as part of your build/release process:

m install --save-dev @polymer/gen-typescript-declarations

Add a gen-tsd script to your package.json:


.
cripts": {
"gen-tsd": "gen-tsd"


If you're using Bower, ensure you run npm run gen-tsd to generate the latest typings and commit them to your repository before tagging each release.

If you're using NPM, you can instead add this script to the NPM prepack script to generate and include typings in your NPM package every time you publish.

Config options

By default the gen-tsd command will read a file called gen-tsd.json in your root directory. It has the following options:

Using as a module

You can also use this package as a module:

rt {generateDeclarations} from 'gen-typescript-declarations';

t config = {
xclude": [
"test/**",

emoveReferences": [
"../shadycss/apply-shim.d.ts",

ddReferences": {
"lib/utils/boot.d.ts": [
  "extra-types.d.ts"
]

enameTypes": {
"Polymer_PropertyEffects": "Polymer.PropertyEffects"



 map of d.ts file paths to file contents.
t declarations = await generateDeclarations('/my/root/dir', config);
FAQ
Why are some typings missing?

This library is based on Polymer Analyzer which has limitations in its static analysis. For certain patterns, Analyzer relies on additional JSDoc annotations.

Can I augment the generated typings with hand-written ones?

Yes, see the addReferences config option above.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.