I submitted a bug report regarding Typescript because I suspect there is an issue, although I'm seeking additional insights here as well.
This is the scenario. When running the following code:
class Person {
@IsValueIn(['PETER', 'JAMES'])
@IsAlpha()
@IsDefined()
public name:string;
}
An error message is displayed:
Error in /turbo_modules/@fireflysemantics/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b1c7d0ddd8d5d0c5dec3f1829f819f8081">[email protected]</a>/bundles/fireflysemantics-validator.umd.js (194:21)
The ValidationContainer
already contains context with signature IsValueIn_Person_name.
However, if we comment out @IsValueIn(['PETER', 'JAMES'])
:
class Person {
//@IsValueIn(['PETER', 'JAMES'])
@IsAlpha()
@IsDefined()
public name:string;
}
No exceptions are raised.
Upon decorator instantiation, a function is called twice (confirmed by logging statements):
/**
* @param target Add a ValidationContext instance.
* @throws Error if attempting to add a ValidationContext with a signature that duplicates that of an instance already contained.
*
* If an exception thrown it indicates that a duplicate class definition exist
* in the runtime. In other words the same class definition is loaded more
* than once because it exists in multiple files.
*
*/
public static addValidationContext(target: ValidationContext): void {
const key: string = getPropertyKey(
target.target.name,
target.propertyName
);
console.log("The property key is: ", key)
console.log("The target signature is: ", target.getSignature())
The following logging statements indicate the duplication issue:
ValidationContainer.ts:69 The target signature is: IsDefined_Person_name
ValidationContainer.ts:68 The property key is: Person_name
ValidationContainer.ts:69 The target signature is: IsAlpha_Person_name
ValidationContainer.ts:68 The property key is: Person_name
ValidationContainer.ts:69 The target signature is: IsValueIn_Person_name
ValidationContainer.ts:68 The property key is: Person_name
ValidationContainer.ts:69 The target signature is: IsValueIn_Person_name
It's evident that IsValueIn_Person_name
is being created twice due to the double decorator instantiation, leading to the exception being raised.
Any thoughts on this?