I'm trying to create a decorator (NonExportable) to tell which fields in a class should not be exported. Here is the 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:
personaFisica.ts
import NonExportable from "../util/nonexportable-decorator"
export class Contribuinte {
ni: string;
@NonExportable()
cpf: number;
@NonExportable()
cnpjEstabelecimento: number;
}
However, apparently is not being recorded anything in metadata, considering that when running the Reflect.isNonExportable is returned a value undefined . That way, it is always returned false by isNonExportable . What am I doing wrong?