|
2 | 2 | title: M Language types |
3 | 3 | description: Describes using types in the Power Query M formula language |
4 | 4 | ms.topic: conceptual |
5 | | -ms.date: 10/7/2024 |
| 5 | +ms.date: 1/29/2025 |
6 | 6 | ms.custom: "nonautomated-date" |
7 | 7 | ms.subservice: m-specification |
8 | 8 | --- |
@@ -32,19 +32,18 @@ All types that are not members of the closed set of primitive types plus their n |
32 | 32 | _type-expression:<br/> |
33 | 33 | primary-expression_<br/> |
34 | 34 | `type` _primary-type<br/> |
35 | | -type:<br/> |
36 | | - primary-expression<br/> |
37 | | - primary-type<br/> |
38 | 35 | primary-type:<br/> |
39 | | - primitive-type<br/> |
| 36 | + primitive-or-nullable-primitive-type<br/> |
40 | 37 | record-type<br/> |
41 | 38 | list-type<br/> |
42 | 39 | function-type<br/> |
43 | 40 | table-type<br/> |
44 | | - nullable-type<br/> |
45 | | -primitive-type:_ one of<br/> |
| 41 | + nullable-type_<br /> |
| 42 | +_primitive-or-nullable-primitive-type:_<br/> |
| 43 | + `nullable`_<sub>opt</sub> primitive-type_<br /> |
| 44 | +_primitive-type:_ one of<br/> |
46 | 45 | `any anynonnull binary date datetime datetimezone duration function list logical`<br/> |
47 | | - `none null number record table text time type` |
| 46 | + `none null number record table text time type`<br/> |
48 | 47 |
|
49 | 48 | The _primitive-type_ names are _contextual keywords_ recognized only in a _type_ context. The use of parentheses in a _type_ context moves the grammar back to a regular expression context, requiring the use of the type keyword to move back into a type context. For example, to invoke a function in a _type_ context, parentheses can be used: |
50 | 49 |
|
@@ -95,7 +94,7 @@ Value.Type( 1 as number ) // type number |
95 | 94 | {2} as text // error, type mismatch |
96 | 95 | ``` |
97 | 96 |
|
98 | | -Note that the `is` and `as` operators only accept nullable primitive types as their right operand. M does not provide means to check values for conformance to custom types. |
| 97 | +Note that the `is` and `as` operators only accept a _primitive or nullable primitive type_ (i.e. a _non-custom type_) as their right operand. M does not provide means to check values for conformance to custom types. |
99 | 98 |
|
100 | 99 | A type `X` is _compatible_ with a type `Y` if and only if all values that conform to `X` also conform to `Y`. All types are compatible with type `any` and no types (but `none` itself) are compatible with type `none`. The following graph shows the compatibility relation. (Type compatibility is reflexive and transitive. It forms a lattice with type `any` as the top and type `none` as the bottom value.) The names of abstract types are set in _italics_. |
101 | 100 |
|
@@ -210,28 +209,28 @@ A conforming value may contain field names not listed in the field specification |
210 | 209 |
|
211 | 210 | Any function value conforms to the primitive type `function`, which does not place any restrictions on the types of the function's formal parameters or the function's return value. A custom _function-type value_ is used to place type restrictions on the signatures of conformant function values. |
212 | 211 |
|
213 | | -_function-type:_<br/> |
214 | | - `function (` _parameter-specification-list<sub>opt</sub>_ `)` _function-return-type<br/> |
| 212 | +function-type:_<br/> |
| 213 | + `function (` _parameter-specification-list<sub>opt</sub>_ `)` _return-type<br/> |
215 | 214 | parameter-specification-list:<br/> |
216 | 215 | required-parameter-specification-list<br/> |
217 | 216 | required-parameter-specification-list_ `,` _optional-parameter-specification-list<br/> |
218 | 217 | optional-parameter-specification-list<br/> |
219 | 218 | required-parameter-specification-list:<br/> |
220 | 219 | required-parameter-specification<br/> |
221 | | - required-parameter-specification_ `,` _required-parameter-specification-list<br/> |
| 220 | + required-parameter-specification_ `,` _required-parameter-specification-list<br/> |
222 | 221 | required-parameter-specification:<br/> |
223 | 222 | parameter-specification<br/> |
224 | 223 | optional-parameter-specification-list:<br/> |
225 | 224 | optional-parameter-specification<br/> |
226 | | - optional-parameter-specification_ `,` _optional-parameter-specification-list<br/> |
| 225 | + optional-parameter-specification_ `,` _optional-parameter-specification-list<br/> |
227 | 226 | optional-parameter-specification:_<br/> |
228 | | - `optional` _parameter-specification<br/> |
| 227 | + `optional` _parameter-specification<br/> |
229 | 228 | parameter-specification:<br/> |
230 | | - parameter-name parameter-type<br/> |
231 | | -function-return-type:<br/> |
232 | | - assertion<br/> |
233 | | -assertion:_<br/> |
234 | | - `as` _nullable-primitive-type_ |
| 229 | + parameter-name parameter-type<br/> |
| 230 | +parameter-type:<br/> |
| 231 | + type-assertion<br/> |
| 232 | +type-assertion:_<br/> |
| 233 | + `as` _type_ |
235 | 234 |
|
236 | 235 | The result of evaluating a _function-type_ is a type value whose base type is `function`. |
237 | 236 |
|
@@ -364,7 +363,7 @@ Value.Type( Value.ReplaceType( {1}, type {number} ) |
364 | 363 |
|
365 | 364 | Type equivalence is not defined in M. An M implementation may optionally choose to use its own rules to perform equality comparisons between type values. Comparing two type values for equality should evaluate to `true` if they are considered identical by the implementation, and `false` otherwise. In either case, the response returned must be consistent if the same two values are repeatedly compared. Note that within a given implementation, comparing some identical type values (such as `(type text) = (type text)`) may return `true`, while comparing others (such as `(type [a = text]) = (type [a = text])`) may not. |
366 | 365 |
|
367 | | -Compatibility between a given type and a nullable primitive type can be determined using the library function `Type.Is`, which accepts an arbitrary type value as its first and a nullable primitive type value as its second argument: |
| 366 | +Compatibility between a given type and either a primitive type or a nullable primitive type can be determined using the library function `Type.Is`, which accepts an arbitrary type value as its first argument and a primitive or nullable primitive type value as its second argument: |
368 | 367 |
|
369 | 368 | ```powerquery-m |
370 | 369 | Type.Is(type text, type nullable text) // true |
|
0 commit comments