Skip to content

Commit

Permalink
fix: setter decorator not working
Browse files Browse the repository at this point in the history
  • Loading branch information
riflowth committed May 11, 2024
1 parent f8ce354 commit 0278b62
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tslombok",
"description": "Lombok for TypeScript",
"version": "1.2.0",
"version": "1.2.6",
"author": "Krid Heprakhone <[email protected]>",
"homepage": "https://github.com/vectier/tslombok",
"bugs": "https://github.com/vectier/tslombok/issues",
Expand Down
26 changes: 12 additions & 14 deletions src/TSLombok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@ export const Getter = (target: Object, propertyKey: string | Symbol): void => {
});
};

export const Setter = (...params: unknown[]): PropertyDecorator => {
return (target: Object, propertyKey: string | Symbol): void => {
if (typeof propertyKey === 'symbol') propertyKey.toString();
const propertyName = propertyKey as string;
const methodName = `set${capitalize(propertyName)}`;
export const Setter = (target: Object, propertyKey: string | Symbol): void => {
if (typeof propertyKey === 'symbol') propertyKey.toString();
const propertyName = propertyKey as string;
const methodName = `set${capitalize(propertyName)}`;

// Define setter method to the target class prototype,
// that set a given value to their own property instance
Object.defineProperty(target, methodName, {
value: function (value: unknown) {
this[propertyName] = value;
},
});
};
}
// Define setter method to the target class prototype,
// that set a given value to their own property instance
Object.defineProperty(target, methodName, {
value: function (value: unknown) {
this[propertyName] = value;
},
});
};
2 changes: 1 addition & 1 deletion src/generator/decorators/SetterDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class SetterDecorator implements MethodGeneratorDecorator {
public createMethodSignature(propertyName: string, returnType: TypeNode): MethodSignature {
return factory.createMethodSignature(
undefined, // No need to have a modifer for interface in declaration merging
`get${capitalize(propertyName)}`,
`set${capitalize(propertyName)}`,
undefined,
undefined,
[factory.createParameterDeclaration(
Expand Down

0 comments on commit 0278b62

Please sign in to comment.