> For the complete documentation index, see [llms.txt](https://docs.novacura.com/flow-connect/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.novacura.com/flow-connect/reference/reference/flowscript/walkthrough/custom-types.md).

# Custom Types

## Type Definitions

FlowScript is a structurally typed language, but it is possible to create named types. Using a named  type allows you to deserialize [JSON](/flow-connect/reference/reference/flowscript/walkthrough/json-module.md), or write groups of functions operating on the same type of data without a lot of repetition.

```typescript
// Example: define a record type called User, then define
// a function which accepts a User as its argument.
type User = {
    name: text,
    email: text,
    gropIds: number*
};

function getEmail(user: User) => user.email;

let u = new User {
    name: "Florian",
    email: "florian@example.com",
    gropIds: [1, 2]
};

return getEmail(u);
```

Note that all values in this program are still structurally typed. In other words, the following permutation is perfectly valid:

```typescript
// assuming the same definitions as above

let u2 = {
    name: "Joe",
    email: "joe@example.com",
    gropIds: [0, 8],
    department: "Accounting" // this member is not in the type.
};
return getEmail(u2);
```

In other words, the getEmail function accepts all records which have *at least* the members defined in the User type. There is no requirement that they be created using the **new User** construct, and they are allowed to have additional members not listed in the type. (For in-depth information, refer to the [appendix on subtyping rules](/flow-connect/reference/reference/flowscript/walkthrough/appendix-subtyping-rules.md).)

## Advanced: Generic type definitions

Like functions, types can be generic. Type variables are written in angle brackets after the type name.

```typescript
type Response<T> = {
    timestamp: datetime,
    data: T
};

function getSomeNumber(): Response<number> {
    return new Response<number> { timestamp: now(), data: random(1, 10) };
}

return getSomeNumber();
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.novacura.com/flow-connect/reference/reference/flowscript/walkthrough/custom-types.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
