Type.ForFunction
TypeCreates a function type from a signature record and minimum parameter count.
Syntax
Type.ForFunction(signature as record, min as number) as typeParameters
| Name | Type | Required | Description |
|---|---|---|---|
signature | record | Yes | A record with ReturnType (a type) and Parameters (a list of records with Name, Type, and optional Description). |
min | number | Yes | The minimum number of required parameters. |
Return Value
type — A function type matching the specified signature.
Remarks
Type.ForFunction constructs a function type from a descriptive record. The signature record has two fields:
- ReturnType — the return type of the function.
- Parameters — a list of records, each with Name (text), Type (type), and optionally Description (text).
The min parameter specifies how many of the parameters are required. Parameters beyond min are treated as optional.
This function is typically used with Function.From to create dynamically typed custom functions, or with Value.ReplaceType to add parameter metadata to an existing function so it renders properly in the Power Query UI.
### Typical pattern
``powerquery
let
Signature = [
ReturnType = type text,
Parameters = {
[Name = "input", Type = type text, Description = "The input text"],
[Name = "prefix", Type = type text, Description = "Optional prefix"]
}
],
FnType = Type.ForFunction(Signature, 1) // 1 required, 1 optional
in
FnType
``
Examples
Example 1: Create a function type and verify it
let
Signature = [
ReturnType = type number,
Parameters = {
[Name = "a", Type = type number],
[Name = "b", Type = type number]
}
],
FnType = Type.ForFunction(Signature, 2),
IsFunction = Type.Is(FnType, type function)
in
#table({"Description", "IsFunction"}, {{"type function (a as number, b as number) as number", IsFunction}})Description | IsFunction | |
|---|---|---|
| 1 | type function (a as number, b as number) as number | TRUE |