Typed workflows
Typed workflows are a preview feature. The syntax and behavior may change in future releases.
Typed workflows let you declare the types of a named workflow's inputs and outputs in its take: and emit: sections. The Nextflow language server uses the annotations to validate the values that enter and leave the workflow against their declared types.
nextflow.enable.types = true
workflow hello_bye {
take:
samples: Channel<Path>
main:
ch_hello = hello(samples)
val_bye = bye(ch_hello.collect())
emit:
result: Value<Path> = val_bye
}
In the above example, hello_bye takes a channel of files (Channel<Path>) and emits a dataflow value with a single file (Value<Path>).
Typed workflows require the nextflow.enable.types feature flag. For an overview of static typing and how to enable it, see Static typing. For the complete syntax reference, see Workflow (typed).
Supported types
Channels and values are modeled using the dataflow types:
- Use
Channel<V>for a channel of values. - Use
Value<V>for a single dataflow value.
The element type V can be any standard type, such as Path, String, or a record.
Workflow inputs can be channels, dataflow values, or regular values. Workflow outputs can be channels or dataflow values.
Restricted syntax
The following syntax patterns are no longer supported in typed workflows:
-
Using
Channelto access channel factories (usechannelinstead) -
Using implicit closure parameters (declare parameters explicitly instead)
-
Using
setortapto assign channels (use standard assignments instead) -
Composing dataflow logic with
|and&(use standard method calls instead) -
Accessing process and workflow outputs via
.out(use standard assignments instead)
For more information about preparing existing code, see Preparing for static typing.
Operators
The operator library supports static typing and records. All operators work in both typed and legacy workflows, but only a core subset of operators is recommended for static typing.
For more information about best practices when migrating existing code, see Using operators with static typing.
Validation
The language server validates each workflow input and output against its declared type. Calling a workflow with an argument whose type does not match its take: declaration, or emitting a value that does not match its emit: declaration, is reported as an error before the pipeline runs.
See also
- Static typing: Overview of static typing and how to enable it.
- Standard types: The standard types available for annotations.
- Operators: The core operators recommended for static typing.