This package has been deprecated

Author message:

The package has been renamed to proto-decorator. There are no breaking changes.

typescript-proto-decorator
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Typescript Proto Decorator

Build Status Greenkeeper badge

Installation

npm install typescript-proto-decorator

API

/**
 * Sets a value on the class' prototype
 * @param value The value to set
 * @param options Options to set. Defaults to configurable, enumerable and writable.
 */
function Proto(value: any, options?: Pick<PropertyDescriptor, 'configurable' | 'enumerable' | 'writable'>): PropertyDecorator;

Usage

import {Proto} from 'typescript-proto-decorator';
 
class MyClass {
  
  // set MyClass.prototype.foo = 'bar'
  @Proto('bar')
  public foo: string;
  
  // set MyClass.prototype.count = 1; It will be non-enumerable, non-writable.
  @Proto(1, {writable: false, enumerable: false})
  public readonly count: number;
}

Shortcuts

  • You can use @Proto.immutable as a shortcut for {configurable: false, enumerable: true, writable: false}.
  • You can use @Proto.hidden as a shortcut for {configurable: true, enumerable: false, writable: true}.
  • You can use @Proto.immutableHidden as a shortcut for {configurable: false, enumerable: false, writable: false}.

The UMD global is ProtoDecorator.

Package Sidebar

Install

npm i typescript-proto-decorator

Weekly Downloads

5

Version

2.1.0

License

MIT

Unpacked Size

17.2 kB

Total Files

10

Last publish

Collaborators

  • alorel