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

Incorrect type inference from Stackbit config #363

Closed
seancdavis opened this issue Jan 27, 2023 · 1 comment
Closed

Incorrect type inference from Stackbit config #363

seancdavis opened this issue Jan 27, 2023 · 1 comment
Milestone

Comments

@seancdavis
Copy link
Collaborator

If I have the following in a Stackbit model definition:

export const ModelName = {
  // ...
  fields: [
    {
      name: 'fieldName',
      type: 'string',
      hidden: true,
      required: false,
    }
  ]
}

The type that is generated is:

type ModeName = {
  // ...
  fieldName?: string | undefined
}

Great. Works like I would expect. Now if I add a default (initial value for Stackbit):

export const ModelName = {
  // ...
  fields: [
    {
      name: 'fieldName',
      type: 'string',
      hidden: true,
      required: false,
      default: '',
    }
  ]
}

The type that is generated is:

type ModeName = {
  // ...
  fieldName: string
}

Contentlayer assumes this is now a required field for some reason.


Note that this would be fine if I could override it. The problem is that I also can't just override a type. If I were to do something like this:

const documentTypes = stackbitConfigToDocumentTypes(stackbitConfig as any, {
  documentTypes: {
    ModelName: {
      fields: {
        fieldName: { ...stackbitConfig.models.ModelName.fields[0], required: false }
      }
    }
  }
})

There are two problems here:

  1. Stackbit's TS definition won't let me drill into models.
  2. Contentlayer won't let me define anything in a field other than the type property.

So there may be two issues in here.

cc @schickling @smnh

@schickling schickling added this to the 0.3.1 milestone Feb 14, 2023
@schickling
Copy link
Collaborator

This should be addressed with the 0.3.1 release. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants