Skip to content

Type annotations #6278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Type annotations #6278

wants to merge 1 commit into from

Conversation

bentsherman
Copy link
Member

@bentsherman bentsherman commented Jul 15, 2025

This PR adds Nextflow-style type annotations for workflows, functions, and local variables.

Waiting for #5929 to be merged

@bentsherman bentsherman requested a review from pditommaso July 15, 2025 17:19
Copy link

netlify bot commented Jul 15, 2025

Deploy Preview for nextflow-docs-staging ready!

Name Link
🔨 Latest commit 59f9378
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/687ad0f9d49c5d000879016b
😎 Deploy Preview https://deploy-preview-6278--nextflow-docs-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bentsherman bentsherman added this to the 25.10 milestone Jul 15, 2025
@bentsherman bentsherman force-pushed the type-annotations branch 3 times, most recently from 91d5453 to d737101 Compare July 16, 2025 17:19
Signed-off-by: Ben Sherman <[email protected]>
Copy link
Collaborator

@christopher-hakkaart christopher-hakkaart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't spot any errors/typos. I've made some suggests to move the language to a active voice. Feel free to approve/reject as you see fit.


<h3>Type annotations</h3>

Type annotations are a way to denote the *type* of a variable. They are useful both for documenting and validating your pipeline code.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Type annotations are a way to denote the *type* of a variable. They are useful both for documenting and validating your pipeline code.
You can use type annotations to denote the **type** of a variable. They help document and validate your pipeline code.

}
```

The following declarations can be annotated with types:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following declarations can be annotated with types:
You can annotate the following declarations with types:


Type annotations can refer to any of the {ref}`standard types <stdlib-types>`.

Type annotations can be appended with `?` to denote that the value can be `null`:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Type annotations can be appended with `?` to denote that the value can be `null`:
You can append an `?` to type annotations to denote that the value can be `null`:

```

:::{note}
While Nextflow inherited type annotations of the form `<type> <name>` from Groovy, this syntax was deprecated in the {ref}`strict syntax <strict-syntax-page>`. Groovy-style type annotations are still allowed for functions and local variables, but will be automatically converted to Nextflow-stype type annotations when formatting code with the language server or `nextflow lint`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
While Nextflow inherited type annotations of the form `<type> <name>` from Groovy, this syntax was deprecated in the {ref}`strict syntax <strict-syntax-page>`. Groovy-style type annotations are still allowed for functions and local variables, but will be automatically converted to Nextflow-stype type annotations when formatting code with the language server or `nextflow lint`.
Nextflow previously inherited type annotations in the form `<type> <name>` from Groovy, but this syntax is now deprecated under the <strict-syntax-page>`. Groovy-style type annotations are still allowed for functions and local variables. However, the language server and `nextflow lint` will automatically convert them to Nextflow-style type annotations when formatting code.

@@ -655,7 +655,7 @@ hello

### Input tuples (`tuple`)

The `tuple` qualifier allows you to group multiple values into a single input definition. It can be useful when a channel emits tuples of values that need to be handled separately. Each element in the tuple is associated with a corresponding element in the `tuple` definition. For example:
The `tuple` qualifier allows you to group multiple values into a single input definition. It can be useful when a channel emits {ref}`tuples <script-tuples>` of values that need to be handled separately. Each element in the tuple is associated with a corresponding element in the `tuple` definition. For example:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `tuple` qualifier allows you to group multiple values into a single input definition. It can be useful when a channel emits {ref}`tuples <script-tuples>` of values that need to be handled separately. Each element in the tuple is associated with a corresponding element in the `tuple` definition. For example:
The `tuple` qualifier groups multiple values into a single input definition. It can be useful when a channel emits {ref}`tuples <script-tuples>` of values that need to be handled separately. Each element in the tuple is associated with a corresponding element in the `tuple` definition. For example:

is_male = person[2]
```

Tuples can be destructured in assignments:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Tuples can be destructured in assignments:
You can destroy tuples in assignments:

def meta: Map = [:]
```

While Groovy-style type annotations are still supported, the linter and language server will automatically convert them to Nextflow-style type annotations when formatting code. Groovy-style type annotations will not be supported in a future version.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
While Groovy-style type annotations are still supported, the linter and language server will automatically convert them to Nextflow-style type annotations when formatting code. Groovy-style type annotations will not be supported in a future version.
Groovy-style type annotations are supported. However, the language server and `nextflow lint` will automatically convert them to Nextflow-style type annotations when formatting code. Groovy-style type annotations will not be supported in a future version.

@@ -368,21 +380,26 @@ def map = (Map) readJson(json) // soft cast
def map = readJson(json) as Map // hard cast
```

In the strict syntax, only hard casts are supported. However, hard casts are discouraged because they can cause unexpected behavior if used improperly. Groovy-style type annotations should be used instead:
In the strict syntax, only hard casts are supported.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In the strict syntax, only hard casts are supported.
Only hard casts are supported in the strict syntax.

In the strict syntax, only hard casts are supported. However, hard casts are discouraged because they can cause unexpected behavior if used improperly. Groovy-style type annotations should be used instead:
In the strict syntax, only hard casts are supported.

When casting a value to a different type, it is always better to use an explicit method if one is available. For example, to parse a string as a number:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
When casting a value to a different type, it is always better to use an explicit method if one is available. For example, to parse a string as a number:
Always use an explicit method to cast a value to a different type if one is available. For example, to parse a string as a number:


When converting a value to a different type, it is better to use an explicit method rather than a cast. For example, to parse a string as a number:
In cases where a function returns an unknown type, use a type annotation:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In cases where a function returns an unknown type, use a type annotation:
Use a type annotation when a function returns an unknown type:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants