Type.ReplaceFacets
TypeReturns a new type with the specified facets replaced, allowing customization of type constraints such as precision and scale.
Syntax
Type.ReplaceFacets(type as type, facets as record) as typeParameters
| Name | Type | Required | Description |
|---|---|---|---|
type | type | Yes | The base type whose facets are replaced. |
facets | record | Yes | A record specifying the facet values to set (e.g., [Precision = 10, Scale = 2]). |
Return Value
type — A new type with the provided facets applied.
Remarks
Type.ReplaceFacets returns a new type value that is identical to the input type except that the facets specified in the facets record are replaced with the provided values. Facets are type constraint properties beyond the base kind — for example, Precision and Scale for numeric types, or MaxLength for text types.
The facets record only needs to include the fields you want to set. Any facets not mentioned in the record retain their values from the source type. To inspect the current facets of a type before replacing them, use Type.Facets.
Type.ReplaceFacets is most useful in custom connector development, where you need to construct M type values that carry database-level schema constraints (such as DECIMAL(10, 2) precision from a SQL source). It is the write-side counterpart to the read-side Type.Facets. The resulting type can be applied to a value with Value.ReplaceType.
Note that setting facets does not validate or constrain actual data values at runtime — M's type system uses facets as metadata, not as enforcement mechanisms during evaluation.
Examples
Example 1: Set precision and scale on a number type
let
BaseType = type number,
Constrained = Type.ReplaceFacets(BaseType, [Precision = 10, Scale = 2])
in
Type.Facets(Constrained)The final output — applies Precision = 10 and Scale = 2 facets to the number type using Type.ReplaceFacets, then calls Type.Facets to inspect the resulting facet values.
Name | Value | |
|---|---|---|
| 1 | Precision | 10 |
| 2 | Scale | 2 |
Example 2: Set MaxLength on a text type
let
T = Type.ReplaceFacets(type text, [MaxLength = 100])
in
Type.Facets(T)Name | Value | |
|---|---|---|
| 1 | MaxLength | 100 |
Example 3: Clear a facet by setting it to null
let
Constrained = Type.ReplaceFacets(type number, [Precision = 10, Scale = 2]),
Cleared = Type.ReplaceFacets(Constrained, [Precision = null, Scale = null])
in
Type.Facets(Cleared)The final output — removes both facets by setting them to null with another call to Type.ReplaceFacets, then calls Type.Facets to confirm the facet values are now null.
Name | Value | |
|---|---|---|
| 1 | Precision | null |
| 2 | Scale | null |