A decorator-based module that allows developer to reduce boilerplate code, make your code more fatty-free.
TSLombok use TypeScript Compiler API behind the scene to read the Abstract Syntax Tree (AST) of your TypeScript source code and then determine what should declaration to generate into .d.ts (declaration file) for using declaration merging technique. This technique allows TSLombok to merge a magic method from TSLombok into the existing decorated class.
Special thanks to Lombok. This project (TSLombok) is strongly inspired from their.
Without any IDE extension installation, only TSLombok is installed.
Install TSLombok module
# For NPM user
npm install tslombok
# For Yarn user
yarn install tslombok
# For PNPM user
pnpm install tslombok
Then run TSLombok generator engine with npx tslombok
and ready to go!
(We plan to remove this step and make TSLombok a TSC plugin for automatically starting up)
- @Getter - The property decorator to create a getter method automatically.
A getter method returns the property, and is namedgetFoo
if the property is calledfoo
. - @Setter - The property decorator to create a setter method automatically.
A setter method is namedsetFoo
if the property is calledfoo
, returns void, and takes 1 parameter of the same type as the property to set the field to the given value.
Example:
export class People {
@Getter
@Setter
private readonly name: string = 'John Doe';
}
// You can call getter and setter seamlessly without any TypeScript warning!
const people = new People();
people.getName(); // 'John Doe'
people.setName('Jane Doe');
people.getName(); // 'Jane Doe'
- TSLombok generator engine reads your source code and determines what parameter type or return type should be by reading
TypeReference
ofPropertyDeclaration
on AST, so you must explicitly define the type. - We recommend you to use this TypeScript ESLint rule to enforce type annotations on member variables of classes.
There are many ways in which you can participate in this project, for example:
- Submit bugs and feature requests.
- Review source code changes.
- Fixing issues and contributing directly to the code base by submitting pull requests.
Copyright (c) Vectier. All rights reserved.
Licensed under the MIT license.