packages/reflection/README.md
MikroORM metadata provider based on ts-morph. Extracts property types from TypeScript source files at runtime, allowing you to omit explicit type declarations in decorators.
npm install @mikro-orm/reflection
Register the TsMorphMetadataProvider in your ORM configuration:
import { MikroORM } from '@mikro-orm/postgresql';
import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
const orm = await MikroORM.init({
entities: [Author, Book],
dbName: 'my-db',
metadataProvider: TsMorphMetadataProvider,
});
With the reflection provider, you can omit explicit type options in your decorators — the provider infers them from the TypeScript source:
@Entity()
class Author {
@PrimaryKey()
id!: number; // type inferred as 'number'
@Property()
name!: string; // type inferred as 'string'
@ManyToMany(() => Book)
books = new Collection<Book>(this); // relation type inferred
}
Note: The default SWC-based metadata provider handles most use cases without needing
ts-morph. This package is only needed for advanced scenarios where SWC metadata is insufficient.
See the official MikroORM documentation.
Copyright © 2018-present Martin Adámek. Licensed under the MIT License.