diff --git a/docs/docs/decorators.md b/docs/docs/decorators.md index 48f24238ad43..f138101092e6 100644 --- a/docs/docs/decorators.md +++ b/docs/docs/decorators.md @@ -35,26 +35,27 @@ export class Author { ... } `@Property()` decorator is used to define regular entity property. All following decorators extend the `@Property()` decorator, so you can also use its parameters there. -| Parameter | Type | Optional | Description | -|--------------------|---------------------------------------------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `fieldName` | `string` | yes | Override default property name (see [Naming Strategy](./naming-strategy.md)). | -| `type` | `string` | `Constructor` | `Type` | yes | Explicitly specify the runtime type (see [Metadata Providers](./metadata-providers.md) and [Custom Types](./custom-types.md)). | -| `returning` | `boolean` | yes | Whether this property should be part of `returning` clause. Works only in PostgreSQL and SQLite drivers. | -| `onUpdate` | `() => any` | yes | Automatically update the property value every time entity gets updated. | -| `persist` | `boolean` | yes | Set to `false` to define [Shadow Property](serializing.md#shadow-properties). | -| `hydrate` | `boolean` | yes | Set to `false` to disable hydration of this property. Useful for persisted getters. | -| `hidden` | `boolean` | yes | Set to `true` to omit the property when [Serializing](serializing.md). | -| `groups` | `string[]` | yes | Specify serialization groups for [explicit serialization](serializing.md#explicit-serialization). If a property does not specify any group, it will be included, otherwise only properties with a matching group are included. | -| `columnType` | `string` | yes | Specify exact database column type for [Schema Generator](schema-generator.md). **(SQL only)** | -| `length` | `number` | yes | Length/precision of database column, used for `datetime/timestamp/varchar` column types for [Schema Generator](schema-generator.md). **(SQL only)** | -| `default` | `any` | yes | Specify default column value for [Schema Generator](schema-generator.md). **(SQL only)** | -| `unique` | `boolean` | yes | Set column as unique for [Schema Generator](schema-generator.md). **(SQL only)** | -| `nullable` | `boolean` | yes | Set column as nullable for [Schema Generator](schema-generator.md). **(SQL only)** | -| `unsigned` | `boolean` | yes | Set column as unsigned for [Schema Generator](schema-generator.md). **(SQL only)** | -| `comment` | `string` | yes | Specify comment of column for [Schema Generator](schema-generator.md). **(SQL only)** | -| `version` | `boolean` | yes | Set to true to enable [Optimistic Locking](transactions.md#optimistic-locking) via version field. **(SQL only)** | -| `concurrencyCheck` | `boolean` | yes | Set to true to enable [Concurrency Check](transactions.md#concurrency-checks) via concurrency fields. | -| `customOrder` | `string[]` | `number[]` | `boolean[]` | yes | Specify a custom order for the column. **(SQL only)** | +| Parameter | Type | Optional | Description | +|--------------------|---------------------------------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `fieldName` | `string` | yes | Override default property name (see [Naming Strategy](./naming-strategy.md)). | +| `type` | `string` | `Constructor` | `Type` | yes | Explicitly specify the property type. This value is mapped based on the current driver (see [Metadata Providers](./metadata-providers.md) and [Custom Types](./custom-types.md)). | +| `runtimeType` | `string` | yes | Runtime type of the property. This is the JS type that your property is mapped to, e.g. `string` or `number`, and is normally inferred automatically via `reflect-metadata`. In some cases, the inference won't work, and you might need to specify the `runtimeType` explicitly - the most common one is when you use a union type with null like `foo: number | null`. | +| `returning` | `boolean` | yes | Whether this property should be part of `returning` clause. Works only in PostgreSQL and SQLite drivers. | +| `onUpdate` | `() => any` | yes | Automatically update the property value every time entity gets updated. | +| `persist` | `boolean` | yes | Set to `false` to define [Shadow Property](serializing.md#shadow-properties). | +| `hydrate` | `boolean` | yes | Set to `false` to disable hydration of this property. Useful for persisted getters. | +| `hidden` | `boolean` | yes | Set to `true` to omit the property when [Serializing](serializing.md). | +| `groups` | `string[]` | yes | Specify serialization groups for [explicit serialization](serializing.md#explicit-serialization). If a property does not specify any group, it will be included, otherwise only properties with a matching group are included. | +| `columnType` | `string` | yes | Specify exact database column type for [Schema Generator](schema-generator.md). **(SQL only)** | +| `length` | `number` | yes | Length/precision of database column, used for `datetime/timestamp/varchar` column types for [Schema Generator](schema-generator.md). **(SQL only)** | +| `default` | `any` | yes | Specify default column value for [Schema Generator](schema-generator.md). **(SQL only)** | +| `unique` | `boolean` | yes | Set column as unique for [Schema Generator](schema-generator.md). **(SQL only)** | +| `nullable` | `boolean` | yes | Set column as nullable for [Schema Generator](schema-generator.md). **(SQL only)** | +| `unsigned` | `boolean` | yes | Set column as unsigned for [Schema Generator](schema-generator.md). **(SQL only)** | +| `comment` | `string` | yes | Specify comment of column for [Schema Generator](schema-generator.md). **(SQL only)** | +| `version` | `boolean` | yes | Set to true to enable [Optimistic Locking](transactions.md#optimistic-locking) via version field. **(SQL only)** | +| `concurrencyCheck` | `boolean` | yes | Set to true to enable [Concurrency Check](transactions.md#concurrency-checks) via concurrency fields. | +| `customOrder` | `string[]` | `number[]` | `boolean[]` | yes | Specify a custom order for the column. **(SQL only)** | > You can use property initializers as usual. diff --git a/packages/core/src/decorators/Property.ts b/packages/core/src/decorators/Property.ts index 28087e79c808..4cd29731a049 100644 --- a/packages/core/src/decorators/Property.ts +++ b/packages/core/src/decorators/Property.ts @@ -78,6 +78,11 @@ export type PropertyOptions = { * @see https://mikro-orm.io/docs/custom-types */ type?: keyof typeof types | 'ObjectId' | Date | Constructor | Constructor> | Type | (() => unknown) | ColumnType | AnyString; + /** + * Runtime type of the property. This is the JS type that your property is mapped to, e.g. `string` or `number`, and is normally inferred automatically via `reflect-metadata. + * In some cases, the inference won't work, and you might need to specify the `runtimeType` explicitly - the most common one is when you use a union type with null like `foo: number | null`. + */ + runtimeType?: string; /** * Set length of database column, used for datetime/timestamp/varchar column types for {@link https://mikro-orm.io/docs/schema-generator Schema Generator}. (SQL only) */ diff --git a/tests/issues/GH4899.test.ts b/tests/issues/GH4899.test.ts index 27df133de550..ea730109dcaf 100644 --- a/tests/issues/GH4899.test.ts +++ b/tests/issues/GH4899.test.ts @@ -47,7 +47,6 @@ beforeAll(async () => { orm = await MikroORM.init({ dbName: ':memory:', entities: [UserSkill, User, Skill], - // debug: true, }); await orm.schema.createSchema(); }); diff --git a/tests/issues/GH5527.test.ts b/tests/issues/GH5527.test.ts index 18773328cbec..b69691581fe0 100644 --- a/tests/issues/GH5527.test.ts +++ b/tests/issues/GH5527.test.ts @@ -30,7 +30,6 @@ let orm: MikroORM; beforeAll(async () => { orm = await MikroORM.init({ dbName: '5527', - debug: true, entities: [Test], }); await orm.schema.refreshDatabase();