Skip to content

Add typescript compilation testing #1248

@FedericoBonel

Description

@FedericoBonel

Description

Puck exposes many types in a way that is simple to use from a user’s perspective. However, this relies on a lot of advanced type definitions and TypeScript features, which can easily break if not handled carefully.

Currently, whenever there is a type change, we need to manually verify that the types behave as expected from the user’s point of view. This process involves many variations and edge cases that can be easily overlooked.

Because of this, it would be valuable to have some kind of compilation testing to verify that types behave as expected in all scenarios (e.g., required fields are enforced, unions work correctly, types widen or narrow when they should, etc.).

For example, we should be able to test the following:

import { Config } from "@measured/puck";

// Given:
type Components = { List: { items: { text: string }[] } };

// When:
const config: Config<{
  components: Components;
}> = {
  components: {
    List: {
      fields: {
        items: {
          type: "array",
          arrayFields: {} // Then: Should throw an error since "text" isn't defined
        }
      }
    }
  }
};

Considerations

  • There might be existing libraries that can help with this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions