Skip to content

devpaul/TSDecorators-example

Repository files navigation

Examples of TypeScript Decorator Usage

This repo provides example usage of TypeScript Decorators and Metadata. Hopefully this will provide a base for people to experiment and learn!

These examples were produced based on information presented by Wolk Software Limited's three part series on Decorators & metadata reflection in Typescript: From Novice to Expert, the metadata PR #2589 and rbuckton's ES7 Reflection Prototype. Thanks!

Quickstart

A Quick Tour

/src/examples

This directory has example usage and comments about decorators and metadata. Examples show how to use the four different decorators (class, method, parameter, and property), decorator factories used when parameters are passed in a decorator, and custom metadata usage.

/src/patterns

Includes examples of using decorators to facilitate mixins and dependency injection

/tests/unit

This directory has some unit tests illustrating how the different descriptors behave

Notes

As of version 4.2.0.beta1 grunt-ts doesn't yet have support for the experimentalDecorators flag issue #259. We work around this by declaring --experimentalDecorators in additionalFlags.

Metadata support is polyfilled using reflect-metadata More information about how TypeScript leverages it is here:

Grunt Commands

  • grunt lint - validates style rules
  • grunt test - runs intern's node client
  • grunt test-local - runs intern's runner with local configuration (Selenium required)
  • grunt test-proxy - starts intern's testing proxy
  • grunt test-runner - runs intern's runner (BrowserStack/SauceLabs required)
  • grunt ci - runs tests in a continuous integration environment
  • grunt clean - cleans development work
  • grunt - compiles files

Releases

No releases published

Packages

No packages published