Socket
Socket
Sign inDemoInstall

@madsci/ts-class-initializable

Package Overview
Dependencies
0
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @madsci/ts-class-initializable

TypeScript abstract class enabling instance initialization from a plain object


Version published
Weekly downloads
1
Maintainers
2
Install size
4.86 kB
Created
Weekly downloads
 

Readme

Source

ts-class-initializable

A small helper to enable class instance property initialization from a plain object.

Extend one of the Initializable classes and your class constructor will accept a plain object literal as its first argument, and assign the values to instance properties.

Example
class Foo extends Initializable<Foo> {
  public bar: string;
  public baz: number;
  public optional?: boolean;
}

const instance: Foo = new Foo({
  bar: 'foobar',
  baz: 2,
});

console.log(instance.bar); // 'foobar'
Classes

There are a few flavours:

  • Initializable: the constructor requires a plain object to initialize the instance
  • PartiallyInitializable: the constructor requires a plain object to initialize the instance, but all properties are treated as optional
  • OptionallyInitializable: the constructor may accept a plain object to initialize the instance, or you can do new Foo() without initialization
  • OptionallyPartiallyInitializable: the constructor may accept a plain object to initialize the instance, and all properties are treated as optional

FAQs

Last updated on 05 Jul 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc