https://github.com/vectier/tslombok
Lombok for TypeScript
https://github.com/vectier/tslombok
boilerplate decorators lombok modules node nodejs typescript utilities
Last synced: 6 months ago
JSON representation
Lombok for TypeScript
- Host: GitHub
- URL: https://github.com/vectier/tslombok
- Owner: vectier
- License: mit
- Created: 2023-05-31T15:44:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-11T05:57:48.000Z (over 1 year ago)
- Last Synced: 2025-04-01T08:45:57.417Z (7 months ago)
- Topics: boilerplate, decorators, lombok, modules, node, nodejs, typescript, utilities
- Language: TypeScript
- Homepage:
- Size: 71.3 KB
- Stars: 25
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A decorator-based module that allows developer to reduce boilerplate code, make your code more fatty-free.
**TSLombok** use [TypeScript Compiler API](https://github.com/microsoft/TypeScript/wiki/Using-the-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](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)) for using [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) technique. This technique allows TSLombok to merge a magic method from TSLombok into the existing decorated class.
Special thanks to **[Lombok](https://github.com/projectlombok/lombok)**. This project (TSLombok) is strongly inspired from their.
## Preview
Without any IDE extension installation, only TSLombok is installed.## Getting started
Install TSLombok module```bash
# 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)*## Features
### @Getter / @Setter
- **@Getter** - The property decorator to create a getter method automatically.
A getter method returns the property, and is named `getFoo` if the property is called `foo`.
- **@Setter** - The property decorator to create a setter method automatically.
A setter method is named `setFoo` if the property is called `foo`, returns void, and takes 1 parameter of the same type as the property to set the field to the given value.Example:
```ts
export class People {
@Getter
@Setter
private readonly name: string = 'John Doe';
}
```
```ts
// 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'
```#### Limitation
- TSLombok generator engine reads your source code and determines what parameter type or return type should be by reading `TypeReference` of `PropertyDeclaration` on AST, so you must explicitly define the type.
- We recommend you to use [this TypeScript ESLint rule](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/typedef.md#membervariabledeclaration) to enforce type annotations on member variables of classes.## Contribution
There are many ways in which you can participate in this project, for example:- [Submit bugs and feature requests](https://github.com/vectier/tslombok/issues).
- Review [source code changes](https://github.com/vectier/tslombok/pulls).
- Fixing issues and contributing directly to the code base by [submitting pull requests](https://github.com/vectier/tslombok/pulls).## License
Copyright (c) Vectier. All rights reserved.
Licensed under the [MIT](https://github.com/vectier/tslombok/blob/main/LICENSE) license.