-
Notifications
You must be signed in to change notification settings - Fork 16
Every field is optional in generated types #4
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
Comments
Yeah was wondering the same, this is pretty annoying. |
I agree it's annoying. However, this is a problem (or decision) on either Directus' end or in the |
Because Directus allows you to modify the fields to be retrieved using the |
Did you guys find any workaround? Or did you find another solution? |
you may try setting the field to not null, and see if it helps |
Even ID seems to be optional. But I'll give it a try. |
Wondering if there's any updates on this. interface Products {
id?: number;
title?: string | null
media?: number | MyMediaItem[] | null
} where |
Same brother, same... |
Hello, I encounter the same problem, and here are some informations that may help (or not). First, the OpenAPI spec (OAS) from Directus ( Second, for a given endpoint (for example Lastly, even if you include fields Concerning to composed type problem, one ugly workaround I found so far is to use TypeScript type guards. For example: function hasAuthor(user?: components["schemas"]["whatever"]["user_created"]): user is components["schemas"]["Users"] {
return user !== undefined && user !== null && typeof user === 'object' && 'first_name' in user;
}
export default async function MyPage() {
const whatevers = await directus.request(
readItems('whatever', {
fields: ["foo", { "user_created": ["first_name"]}],
})
);
return (
<div>
{whatevers.map((whatever) => {
return (
<span key={whatever.id}>{hasAuthor(whatever.user_created) && whatever.user_created.first_name}</span>
);
})}
</div>
);
} |
Every field is optional in generated types regardless of settings in Directus.
Any idea why?
The text was updated successfully, but these errors were encountered: