Commit ad5e8e52 authored by nanahira's avatar nanahira

use defineProperty

parent 99ad6ae1
...@@ -146,17 +146,23 @@ export function SchemaClass<T>(originalClass: ClassType<T>) { ...@@ -146,17 +146,23 @@ export function SchemaClass<T>(originalClass: ClassType<T>) {
}); });
Object.setPrototypeOf(newClass, originalClass.prototype); Object.setPrototypeOf(newClass, originalClass.prototype);
for (const field of schemaFields) { for (const field of schemaFields) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment Object.defineProperty(newClass, field, {
// @ts-ignore configurable: true,
newClass[field] = schema[field]; enumerable: true,
writable: true,
value: schema[field],
});
} }
for (const functionField of schemaFunctions) { for (const functionField of schemaFunctions) {
if (newClass[functionField]) { if (newClass[functionField]) {
continue; continue;
} }
// eslint-disable-next-line @typescript-eslint/ban-ts-comment Object.defineProperty(newClass, functionField, {
// @ts-ignore configurable: true,
newClass[functionField] = Schema.prototype[functionField]; enumerable: false,
writable: false,
value: Schema.prototype[functionField],
});
} }
newClass[kSchema] = true; newClass[kSchema] = true;
......
...@@ -41,4 +41,10 @@ describe('Schema registration', () => { ...@@ -41,4 +41,10 @@ describe('Schema registration', () => {
it('should throw if required field is missing', () => { it('should throw if required field is missing', () => {
expect(() => new ConfigWithRequiredFields({})).toThrow(); expect(() => new ConfigWithRequiredFields({})).toThrow();
}); });
it('should act functions of schema', () => {
const schema = Config as Schema<Config>;
const newSchema = schema.description('foo');
expect(newSchema.meta.description).toBe('foo');
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment