Features
A comprehensive set of decorators covering immutability, boilerplate reduction, and common design patterns.
3Immutability
@Record
Creates an immutable data carrier with constructor, readonly properties, Object.freeze, and toString.
1@Record2class User {3 id: number;4 name: string;5}67const user = new User(1, 'John');8console.log(user.toString()); // User(id=1, name=John)9console.log(Object.isFrozen(user)); // true@Value
Alias for @Record. Creates an immutable value class.
1@Value2class Point {3 x: number;4 y: number;5}67const p = new Point(10, 20);@With
Generates withX() methods for creating modified copies of immutable objects.
1@Record2@With3class User {4 id: number;5 name: string;6}78const user = new User(1, 'John');9const updated = user.withName('Jane');1011console.log(user.name); // 'John' (unchanged)12console.log(updated.name); // 'Jane' (new instance)4Boilerplate
@Data
Combines @Getter + @Setter + @ToString + @Equals + @AllArgsConstructor for complete data class functionality.
1@Data2class User {3 id: number;4 name: string;5}67const user = new User(1, 'John');8user.getId(); // 19user.setName('Jane');10user.toString(); // User(id=1, name=Jane)11user.equals(other); // true/false12user.hashCode(); // number@Getter / @Setter
Generate getter and setter methods for all properties.
1@Getter2@Setter3class User {4 id: number;5 name: string;6}78const user = new User();9user.setId(1);10user.setName('John');11console.log(user.getId()); // 112console.log(user.getName()); // 'John'@ToString
Generates a toString() method that includes all fields.
1@ToString2class User {3 id: number;4 name: string;5}67const user = new User();8user.id = 1;9user.name = 'John';10console.log(user.toString()); // "User(id=1, name=John)"@Equals
Generates value-based equals() and hashCode() methods.
1@Equals2class Point {3 x: number;4 y: number;5}67const p1 = new Point(); p1.x = 1; p1.y = 2;8const p2 = new Point(); p2.x = 1; p2.y = 2;910p1.equals(p2); // true11p1.hashCode() === p2.hashCode(); // true3Constructors
@NoArgsConstructor
Generates an empty constructor.
1@NoArgsConstructor2class Config {3 host: string;4 port: number;5}67const config = new Config();8config.host = 'localhost';9config.port = 3000;@AllArgsConstructor
Generates a constructor with all fields as parameters.
1@AllArgsConstructor2class Point {3 x: number;4 y: number;5 z: number;6}78const p = new Point(1, 2, 3);@RequiredArgsConstructor
Generates a constructor with only required fields (non-optional, no initializer).
1@RequiredArgsConstructor2class User {3 id: number; // Required - in constructor4 name: string; // Required - in constructor5 active: boolean = true; // Has initializer - excluded6 nickname?: string; // Optional - excluded7}89const user = new User(1, 'John');10console.log(user.active); // true (default value)3Patterns
@Builder
Implements the builder pattern with a fluent API for object construction.
1@Builder2class User {3 id: number;4 name: string;5 email: string;6}78const user = User.builder()9 .id(1)10 .name('John')11 .email('john@example.com')12 .build();@Singleton
Ensures only one instance exists via getInstance() static method.
1@Singleton2@NoArgsConstructor3class AppConfig {4 apiUrl: string = 'https://api.example.com';5}67const config1 = AppConfig.getInstance();8const config2 = AppConfig.getInstance();9console.log(config1 === config2); // true@Log
Generates a protected logger field using console.
1@Log2class UserService {3 createUser(name: string) {4 this.log.info(`Creating user: ${name}`);5 // ...6 }7}1Validation
@NonNull
Property decorator that validates fields are not null/undefined in the constructor.
1@AllArgsConstructor2class User {3 @NonNull4 id: number;56 @NonNull7 name: string;8}910new User(1, 'John'); // OK11new User(null, 'John'); // Throws: "id cannot be null or undefined"Combining Decorators
Decorators can be combined for full functionality. Mix and match to get exactly what you need:
1import { Record, Equals, With, Builder } from 'ts-lombok-kit/markers';23@Record4@Equals5@With6@Builder7class Product {8 id: number;9 name: string;10 price: number;11}1213// Create with builder14const p1 = Product.builder()15 .id(1)16 .name('Widget')17 .price(9.99)18 .build();1920// Immutable update21const p2 = p1.withPrice(19.99);2223console.log(p1.equals(p2)); // false (different prices)24console.log(p1.toString()); // Product(id=1, name=Widget, price=9.99)25console.log(Object.isFrozen(p1)); // trueReady to get started?
Follow our setup guide to start using ts-lombok-kit in your project.
Get Started