Skip to content

Commit

Permalink
fix(reflection): support virtual method properties
Browse files Browse the repository at this point in the history
Fixes support for having `@Property()` decorator on a method with ts-morph.
  • Loading branch information
B4nan committed Jul 10, 2021
1 parent 872a467 commit 0c82179
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/reflection/src/TsMorphMetadataProvider.ts
Expand Up @@ -95,13 +95,14 @@ export class TsMorphMetadataProvider extends MetadataProvider {

const properties = cls.getInstanceProperties();
const property = properties.find(v => v.getName() === prop.name) as PropertyDeclaration;
const tsType = property.getType();

/* istanbul ignore next */
if (!property) {
return { type: prop.type, optional: prop.nullable };
}

const tsType = property.getType();

if (tsType.isEnum()) {
prop.enum = true;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/features/reflection/entities/Author.ts
Expand Up @@ -52,4 +52,9 @@ export class Author extends BaseEntity {
this.foo = 'bar';
}

@Property({ name: 'code' })
getCode() {
return `${this.email} - ${this.name}`;
}

}

0 comments on commit 0c82179

Please sign in to comment.