# SDK - readUsers with a custom directus\_users field?

**URL:** <https://community.directus.com/t/sdk-readusers-with-a-custom-directus-users-field/1194>\
**Category:** Help\
**Tags:** api\
**Created:** [September 19, 2025, 1:30pm UTC](https://community.directus.com/t/sdk-readusers-with-a-custom-directus-users-field/1194 "2025-09-19T13:30:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chromag](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Chromag](https://community.directus.com/u/Chromag)\
**Post date:** [September 19, 2025, 1:30pm UTC](https://community.directus.com/t/sdk-readusers-with-a-custom-directus-users-field/1194/1 "2025-09-19T13:30:25Z")

</div>

I’m just getting starting with Directus and the SDK. I’m migrating data from a legacy system into Directus using Node and the SDK with Typecript. The first thing I want to migrate is the user data. I created my own DirectusSchema:

```auto
export interface SimpleDirectusUser {
  id: string;
  first_name?: string | null;
  last_name?: string | null;
  email?: string | null;
  legacy_user_id?: string | null;
}

export interface DirectusSchema {
  directus_users?: SimpleDirectusUser[];
}

```

I’ve added a `legacy_user_id` to the internal `directus_users` collection because I need to be able to track that information.

I’m trying to query Directus with the SDK to check if the user has already been migrated:

```auto
    const directusClient = createDirectus<DirectusSchema>(DIRECTUS_URL).with(staticToken(ADMIN_TOKEN)).with(rest());

    ...

    const users = await directusClient.request(
      readUsers({
        filter: {
          email: {
            _eq: email,
          },
        },
        fields: ['id', 'email', 'first_name', 'last_name', 'legacy_user_id'],
      })
    );

```

However, I get a Typescript error for my `legacy_user_id` field:

> Type ‘“legacy\_user\_id”’ is not assignable to type ‘“id” | “first\_name” | “last\_name” | “email” | “password” | “location” | “title” | “description” | “tags” | “avatar” | “language” | “theme” | “tfa\_secret” | “status” | “role” | … 15 more … | FunctionFields\<…\>’.

Is there a way I can include my custom field in the resulting user object? This seems to work fine if I omit my `legacy_user_id` field. I’ve checked the documentation, github issues, and searched for issues here. Any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![brainslug](https://sea2.discourse-cdn.com/flex002/user_avatar/community.directus.com/brainslug/32/35_2.png) [@brainslug](https://community.directus.com/u/brainslug)\
**Post date:** [September 19, 2025, 4:11pm UTC](https://community.directus.com/t/sdk-readusers-with-a-custom-directus-users-field/1194/5 "2025-09-19T16:11:36Z")

</div>

Must be something specific in the configuration when using `tsc`, I’ve recreated your setup in the TypeScript playground and am not getting a type error there 🤔

```auto
import { createDirectus, staticToken, rest, readUsers } from '@directus/sdk';

export interface SimpleDirectusUser {
  legacy_user_id?: string | null;
}

export interface DirectusSchema {
  directus_users: SimpleDirectusUser;
}

const directusClient = createDirectus<DirectusSchema>('DIRECTUS_URL').with(staticToken('ADMIN_TOKEN')).with(rest());

const users = await directusClient.request(
    readUsers({
    filter: {
        email: {
            _eq: 'email',
        },
    },
    fields: ['id', 'email', 'first_name', 'last_name', 'legacy_user_id'],
    })
);

```

> **[TS Playground - An online editor for exploring TypeScript and JavaScript](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYygUwIYzQEWO5GAVwGcAaOEmLYZAFQgGs0A7C9K9zAEwFUS0UEnAC+cAGZQIIOAHIAAt3xpCpAPQlujWQG4AUHrQAPSLDjAW2KOIzI0cAMqgwAG1zLVJfoMR64cNwBzWwBPAH1SQTDgbgB+AC5KGCgLQLgAHzgWIhcXfREDY1N4CysbOzg8AmISB2QACzQQDF9-JWrSCIEhRKdwNyqVGu8ofINkCBYqOHah0gBhF2BWeABeFHQsdw6SAB5BzzrG5oA+AApZHABJACUAUXm6Xgcw3huAGVkASgA6AHdgDB6mcqDR6ExWBcAII4ACyVwAcmE6AB5ADSdwR31+AKBZw4MDOXy++j0Eym8EiQjg6wwfwwgJmHhqi2Wlh+6AAjkQ0FQzn5-HBNnxuiQzggBf5xMAXFZEhLBYq4E0GS55ZKlYqwmhOYlZCqZbIyBrFSJjabzYLpWgXNwSIkANqyGJGuQGlyu2TSoQwMIsDAgNCelwYKh+gNBiiyIKhLpRF0AXUt-hEXz0JL0QA)**
>
> The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.

---

<div class="post-metadata">

**Author:** ![ahmad\_quvor](https://sea2.discourse-cdn.com/flex002/user_avatar/community.directus.com/ahmad_quvor/32/310_2.png) [@ahmad\_quvor](https://community.directus.com/u/ahmad_quvor)\
**Post date:** [September 19, 2025, 2:21pm UTC](https://community.directus.com/t/sdk-readusers-with-a-custom-directus-users-field/1194/2 "2025-09-19T14:21:39Z")

</div>

Hello @Chromag

Here’s an example code snippet that shows how to extend the `directus_users` type with a custom field like `legacy_user_id`. Hope this helps!

```auto
import {
  authentication,
  createDirectus,
  readUsers,
  rest,
  DirectusUser as DirectusUserType
} from '@directus/sdk';
import { Env } from '~/types';

const { API_URL } = process.env as unknown as Env;

interface DirectusUser extends DirectusUserType {
  legacy_user_id?: string | null;
}

interface Schema {
  directus_users: DirectusUser;
}

export const directus = createDirectus<Schema>(API_URL)
  .with(authentication('json', { autoRefresh: false }))
  .with(rest());

const players = await directus.request(
  readUsers({ fields: ['legacy_user_id'] })
);

```

---

<div class="post-metadata">

**Author:** ![brainslug](https://sea2.discourse-cdn.com/flex002/user_avatar/community.directus.com/brainslug/32/35_2.png) [@brainslug](https://community.directus.com/u/brainslug)\
**Post date:** [September 19, 2025, 3:42pm UTC](https://community.directus.com/t/sdk-readusers-with-a-custom-directus-users-field/1194/3 "2025-09-19T15:42:32Z")

</div>

No need for manually extending the DirectusUsers type (the sdk should handle that) and the type on the Schema is without array `[]` 😃

```auto
interface MySchema {
    // regular collections are array types
    collection_a: CollectionA[];
    // singleton collections are singular types
    collection_c: CollectionC;
    // extend the provided DirectusUser type
    directus_users: CustomUser;
}

interface CustomUser {
    custom_field: string;
} 

```

> **[Advanced Types with the Directus Sdk | Directus Docs](https://directus.io/docs/tutorials/tips-and-tricks/advanced-types-with-the-directus-sdk#custom-fields-on-core-collections)**
>
> Explore our resources and powerful data engine to build your projects confidently.

---

<div class="post-metadata">

**Author:** ![Chromag](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Chromag](https://community.directus.com/u/Chromag)\
**Post date:** [September 19, 2025, 3:56pm UTC](https://community.directus.com/t/sdk-readusers-with-a-custom-directus-users-field/1194/4 "2025-09-19T15:56:28Z")

</div>

> [@ahmad\_quvor](#):
>
> Here’s an example code snippet that shows how to extend the `directus_users` type with a custom field like `legacy_user_id`. Hope this helps!

I tried this as well prior to posting and got the same result. Just to make sure I tried making the change again to test. Here is the updated `DirectusSchema` based on your example:

```auto
import { DirectusUser as DirectusUserType } from '@directus/sdk';

export interface DirectusUser extends DirectusUserType {
  legacy_user_id?: string | null;
}

export interface DirectusSchema {
  directus_users?: DirectusUser;
}

```

Then I tried something basic as an example like the one you provided:

```auto
export const directusClient = createDirectus<DirectusSchema>(DIRECTUS_URL).with(staticToken(ADMIN_TOKEN)).with(rest());

const players = await directusClient.request(readUsers({ fields: ['legacy_user_id'] }));

```

I still get the same error:

> Type ‘“legacy\_user\_id”’ is not assignable to type …

* * *

> [@brainslug](#):
>
> No need for manually extending the DirectusUsers type (the sdk should handle that) and the type on the Schema is without array `[]` 😃

Gah! I fixed this but I’m still getting the same Typescript error. So the original code I posted should work? (after fixing this to not use an array)

This is strictly a typescript error in vscode (and when using `tsc` to build). If I ignore this and run the script from the terminal (using tsx) it works as expected and the `legacy_user_id` is both written and read correctly.

Thanks for all the help and suggestions!

---

<div class="post-metadata">

**Author:** ![Chromag](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Chromag](https://community.directus.com/u/Chromag)\
**Post date:** [September 19, 2025, 4:19pm UTC](https://community.directus.com/t/sdk-readusers-with-a-custom-directus-users-field/1194/6 "2025-09-19T16:19:55Z")

</div>

> [@brainslug](#):
>
> Must be something specific in the configuration when using `tsc`, I’ve recreated your setup in the TypeScript playground and am not getting a type error there 🤔

I figured it out! I almost don’t want to admit what the problem ended up being but if it helps anyone else I guess it’s worth admitting. Well, ok, there were a few problems:

1. Don’t use an array
2. Based on the documentation you linked (thanks for that!) it specifically says this:

> To define custom fields on the core collections, add a type containing only your custom fields as a singular type.

I fixed those two things but i was still getting the same error about my `legacy_user_id`.

Here is what was causing that error with my custom field:

Your example:

```auto
export interface DirectusSchema {
  directus_users: SimpleDirectusUser;
}

```

My original:

```auto
export interface DirectusSchema {
  directus_users?: SimpleDirectusUser;
}

```

Oh that little `?` to make directus\_users an optional property. As soon as I removed that the error cleared up.

Thanks so much for your help!
