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

Type error when using ObjectField type #621

Open
the-code-raccoon opened this issue Sep 23, 2024 · 0 comments
Open

Type error when using ObjectField type #621

the-code-raccoon opened this issue Sep 23, 2024 · 0 comments

Comments

@the-code-raccoon
Copy link

Background

Puck version: 0.16.0

Current Behaviour

I have two components A and B. I want them both to have a title rendered with some settings (ex. text alignment, text size, etc). So I created a function as follows in a separate file that both component A and B can call.

export const titleField: ObjectField = {
  type: 'object',
  objectFields: {
    text: {
      type: 'text',
    },
    subtext: {
      type: 'text',
    },
  },
}

However when I assign titleField to title in the config for my components. I get the following type error

type ComponentAProps = {
  title: {
    text: string
    subtext: string
  }
}

const ComponentA: ComponentConfig<ComponentAProps>  = {
  defaultProps: {
    title: {
      text: "Main text",
      subtext: "Sub text"
    }
  },
  fields: {
    // Type error on the line below
    title: titleField()
  } 
}

With the following error

Type 'ObjectField' is not assignable to type 'Field<{ text: string; subtext: string; }>'.
  Type 'ObjectField' is not assignable to type 'ObjectField<{ text: string; size: string; }>'.
    Type 'ObjectField' is not assignable to type '{ type: "object"; objectFields: { text: Field<string>; size: Field<string>; }; }'.
      Types of property 'objectFields' are incompatible.
        Type '{ [x: string]: Field<any>; }' is missing the following properties from type '{ text: Field<string>; size: Field<string>; }': text, subtext

Please let me know if this isn't an issue and just an error on my end, thanks!

@the-code-raccoon the-code-raccoon changed the title Type error when using ObjectField Type error when using ObjectField type Sep 23, 2024
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

1 participant