Skip to content
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

chore: add doc for external types #2065

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions docs/content/docs/reference/externaltypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
+++
title = "External Types"
description = "Using external types in your modules"
date = 2024-07-12T18:00:00+00:00
updated = 2024-07-12T18:00:00+00:00
draft = false
weight = 110
sort_by = "weight"
template = "docs/page.html"

[extra]
toc = true
top = false
+++

## Using external types

To use an external type in your FTL module schema, declare a type alias over the external type:

```go
//ftl:typealias
type FtlType external.OtherType
```

The external type is widened to `Any` in the FTL schema, and the corresponding type alias will include metadata
for the runtime-specific type mapping:

```
typealias FtlType Any
+typemap go "github.com/external.OtherType"
```

Users can achieve functionally equivalent behavior to using the external type directly by using the declared
alias (`FtlType`) throughout their code. Direct usage of the external type in schema declarations is not supported;
instead, the type alias must be used.

FTL will automatically serialize and deserialize the external type to the strong type indicated by the mapping.

## Cross-Runtime Type Mappings

FTL also provides the capability to declare type mappings for other runtimes. For instance, to include a type mapping for Kotlin, you can
annotate your type alias declaration as follows:

```go
//ftl:typealias
//ftl:typemap kotlin "com.external.other.OtherType"
type FtlType external.OtherType
```

In the FTL schema, this will appear as:

```
typealias FtlType Any
+typemap go "github.com/external.OtherType"
+typemap kotlin "com.external.other.OtherType"
```

This allows FTL to decode the type properly in other languages, for seamless
interoperability across different runtimes.
Loading