Type.ClosedRecord
TypeReturns a closed version of a record type, disallowing fields beyond those declared in the type.
Syntax
Type.ClosedRecord(type as type) as typeParameters
| Name | Type | Required | Description |
|---|---|---|---|
type | type | Yes | A record type to close. Must be a record type. |
Return Value
type — A closed record type derived from the given record type.
Remarks
Type.ClosedRecord converts a record type into a closed record type. In Power Query M's type system, record types are either open or closed:
- An open record type permits values to have fields beyond those declared in the type. The base type record is open.
- A closed record type requires values to have exactly the declared fields — no additional fields are allowed.
Type.ClosedRecord returns the closed version of whatever record type is passed in. If the type is already closed, it is returned unchanged. The declared field names and field types are preserved — only the open/closed flag changes. The complement of this function is Type.OpenRecord.
Closed record types are important in custom connector development and schema enforcement scenarios. When a type is closed, the M engine and tooling know the record's structure is fully specified, which can enable optimizations and stricter validation. Use Type.IsOpenRecord to test whether a type is open or closed before converting.
Examples
Example 1: Close the base record type and verify
let
Closed = Type.ClosedRecord(type record)
in
Type.IsOpenRecord(Closed)Result | |
|---|---|
| 1 | FALSE |
Example 2: Close a typed record with declared fields
let
Open = Type.ForRecord([Name = [Type = type text, Optional = false]], true),
Closed = Type.ClosedRecord(Open)
in
Type.IsOpenRecord(Closed)The final output — converts the open record type to a closed record type using Type.ClosedRecord, then checks Type.IsOpenRecord to confirm it is no longer open.
Result | |
|---|---|
| 1 | FALSE |
Example 3: Round-trip open → close → open preserves field declarations
let
RT = Type.ForRecord([ID = [Type = type number, Optional = false]], false),
Opened = Type.OpenRecord(RT),
Closed = Type.ClosedRecord(Opened),
Fields = Type.RecordFields(Closed)
in
Fields[ID][Type]The final output — retrieves the field descriptors from the closed type using Type.RecordFields, then reads the Type of the ID field to confirm it is type number.
Result | |
|---|---|
| 1 | type number |