Reflection with Property Developer in typescript does not work

Asked

Viewed 83 times

1

I am trying to create a developer (Nonexportable) to inform which fields of a class should not be exported. Follow code:

nonexportable-decorators.ts

const NON_EXPORTABLE_KEY = Symbol("NonExportable");

export default function NonExportable() {
   return Reflect.metadata(NON_EXPORTABLE_KEY, true);
}

export function isNonExportable (target: any, propertyKey: string): boolean {
   return Reflect.getMetadata(NON_EXPORTABLE_KEY, target, propertyKey);
}

The Decorator is being used in the "personal" model, as shown below:

personal Florence.ts

import NonExportable from "../util/nonexportable-decorator"

export class Contribuinte {
    ni: string; 
    @NonExportable()    
    cpf: number;
    @NonExportable()    
    cnpjEstabelecimento: number;
}

However, apparently nothing is being saved to the Media, since when performing the function Reflect.isNonExportable a value is returned Undefined. Thus, it is always returned false by isNonExportable. What am I doing wrong?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.