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., [NumericPrecision = 10, NumericScale = 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, NumericPrecision and NumericScale for numeric types, or MaxLength and IsVariableLength for text types. The facet names are the nine fields returned by Type.Facets.
The facets record lists the facets to set, using the same field names that Type.Facets returns. To inspect a type's current facets, 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 or NVARCHAR(50) length 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, [NumericPrecision = 10, NumericScale = 2])
in
Type.Facets(Constrained)The final output — Type.Facets shows NumericPrecision 10 and NumericScale 2, with every other facet null.
Name | Value | |
|---|---|---|
| 1 | NumericPrecisionBase | null |
| 2 | NumericPrecision | 10 |
| 3 | NumericScale | 2 |
| 4 | DateTimePrecision | null |
| 5 | MaxLength | null |
| 6 | IsVariableLength | null |
| 7 | NativeTypeName | null |
| 8 | NativeDefaultExpression | null |
| 9 | NativeExpression | null |
Example 2: Describe a SQL nvarchar(50) column on a text type
let
T = Type.ReplaceFacets(type text, [MaxLength = 50, IsVariableLength = true, NativeTypeName = "nvarchar"])
in
Type.Facets(T)The final output — Type.Facets reads the facets of T: MaxLength 50, IsVariableLength true, NativeTypeName "nvarchar", and the rest null.
Name | Value | |
|---|---|---|
| 1 | NumericPrecisionBase | null |
| 2 | NumericPrecision | null |
| 3 | NumericScale | null |
| 4 | DateTimePrecision | null |
| 5 | MaxLength | 50 |
| 6 | IsVariableLength | true |
| 7 | NativeTypeName | nvarchar |
| 8 | NativeDefaultExpression | null |
| 9 | NativeExpression | null |
Example 3: Clear facets by setting them to null
let
Constrained = Type.ReplaceFacets(type number, [NumericPrecision = 10, NumericScale = 2]),
Cleared = Type.ReplaceFacets(Constrained, [NumericPrecision = null, NumericScale = null])
in
Type.Facets(Cleared)The final output — Type.Facets confirms every facet is null again.
Name | Value | |
|---|---|---|
| 1 | NumericPrecisionBase | null |
| 2 | NumericPrecision | null |
| 3 | NumericScale | null |
| 4 | DateTimePrecision | null |
| 5 | MaxLength | null |
| 6 | IsVariableLength | null |
| 7 | NativeTypeName | null |
| 8 | NativeDefaultExpression | null |
| 9 | NativeExpression | null |