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:
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?
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 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:
Type ‘“legacy_user_id”’ is not assignable to type …
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.
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:
Don’t use an array
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: