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

[bug]: Required attributes are inferred as optional when generating types #23

Closed
2 of 3 tasks
LuizPelegrini opened this issue Dec 27, 2024 · 1 comment
Closed
2 of 3 tasks
Labels
issue: bug Issue reporting a bug status: intended behavior The behavior corresponds to the specification and won't be addressed

Comments

@LuizPelegrini
Copy link

Bug Description

Moving issue from strapi/strapi repo

Attribute types for both Content-Types and Components are set as optional, even though they're marked as required when generating the types via strapi ts:generate-types command. The issue comes from the optional operator set it here and null type here

Steps to Reproduce

  1. Clone this repo
  2. Generate project types by running npm run strapi ts:generate-types
  3. Update tsconfig to strict mode
  4. Anywhere in your codebase, import Data type from @strapi/strapi
  5. Create a variable and assign the type Data.ContentType<'api::post.post'> or Data.Entity<'api::post.post'>
  6. Variable attributes are all optional

Expected Behavior

Required attributes should not be inferred as optional

Version

1.0.0

Operating System

MacOS

Runtime Environment

Node.js

Logs

No response

Media

Generated types
image

As you can see in the image, all fields (including required fields like title and seo) are set as optional.
image
image

Confirmation Checklist

  • I have checked the existing issues
  • I agree to follow this project's Code of Conduct
  • I would like to work on this issue
@LuizPelegrini LuizPelegrini added issue: bug Issue reporting a bug status: to be confirmed The issue needs to be reproduced or confirmed by a team member labels Dec 27, 2024
@hanpaine hanpaine added the severity: medium If it breaks the basic use of the product but can be worked around label Dec 30, 2024
@github-project-automation github-project-automation bot moved this to To be reviewed (Open) in Developer Experience Squad Dec 30, 2024
@Convly Convly added status: intended behavior The behavior corresponds to the specification and won't be addressed and removed severity: medium If it breaks the basic use of the product but can be worked around status: to be confirmed The issue needs to be reproduced or confirmed by a team member labels Jan 6, 2025
@Convly
Copy link
Member

Convly commented Jan 6, 2025

Hello, thanks for opening this issue.

I'm sorry for the confusion but this is unfortunately not related to the SDK but to our core types.

As Derrick's said in the original issue, this is currently the intended behavior. However, this might lead us to think about how to expose both strict and non-strict versions of a document. (when we'll add the TS support for the SDK (which will allow using generated types from the Strapi apps))

I'm gonna close this one as it's currently not an SDK issue, but I've replied on the original one, happy to continue the discussion there or on our Discord.

@Convly Convly closed this as completed Jan 6, 2025
@github-project-automation github-project-automation bot moved this from To be reviewed (Open) to Fixed/Shipped in Developer Experience Squad Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: bug Issue reporting a bug status: intended behavior The behavior corresponds to the specification and won't be addressed
Projects
Status: Fixed/Shipped
Development

No branches or pull requests

3 participants