https://github.com/devpaul/tsdecorators-example
An example of Typescript Decorators usage
https://github.com/devpaul/tsdecorators-example
decorators example typescript typescript-decorators
Last synced: 10 months ago
JSON representation
An example of Typescript Decorators usage
- Host: GitHub
- URL: https://github.com/devpaul/tsdecorators-example
- Owner: devpaul
- License: other
- Created: 2015-06-27T19:25:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-10T05:00:22.000Z (over 10 years ago)
- Last Synced: 2025-04-12T18:13:09.038Z (10 months ago)
- Topics: decorators, example, typescript, typescript-decorators
- Language: TypeScript
- Size: 160 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](http://blog.wolksoftware.com/decorators-reflection-javascript-typescript),
the metadata [PR #2589](https://github.com/Microsoft/TypeScript/pull/2589) and rbuckton's [ES7 Reflection Prototype](https://github.com/rbuckton/ReflectDecorators).
Thanks!
## Quickstart
* `npm install`
* `grunt test-proxy`
* open [http://localhost:9000/node_modules/intern/client.html?config=_build/tests/intern-local](http://localhost:9000/node_modules/intern/client.html?config=_build/tests/intern-local)
## 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](https://github.com/TypeStrong/grunt-ts/issues/259). We work around this by declaring
`--experimentalDecorators` in `additionalFlags`.
Metadata support is polyfilled using [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)
More information about how TypeScript leverages it is here:
* [TypeScript PR#2589](https://github.com/Microsoft/TypeScript/pull/2589)
* [Typescript issue #2577](https://github.com/Microsoft/TypeScript/issues/2577)
## 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