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

feat: support custom Integration Fields data with catalog-specific types #2

Merged
merged 2 commits into from
Feb 22, 2022

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Feb 22, 2022

Types of changes

  • Chore (a non-breaking change which is related to package maintenance)
  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This PR adds the ability to type Integration Fields fields with custom catalog-specific types.

For example, if you know the object type returned by a Shopify catalog, you can configure the output to include your custom type.

Custom types can be provided to generateTypes()'s fieldConfigs.integrationFields.catalogTypes option:

const model = prismicM.model.customType({
	seed: t.title,
	id: "foo",
	fields: {
		bar: prismicM.model.integrationFields({
			seed: t.title,
			catalog: "baz"
		}),
	},
});

const types = generateTypes({
	customTypeModels: [model],
	fieldConfigs: {
		integrationFields: {
			catalogTypes: {
				baz: "BazType",
			},
		},
	},
});

This will provide the following output (this is not the full output, only the relevant part):

interface FooDocumentData {
	bar: prismicT.IntegrationFields<BazType>;
}

If no provider-specific types are given, the field will be typed as prismicT.IntegrationFields.

Checklist:

  • My change requires an update to the official documentation.
  • All TSDoc comments are up-to-date and new ones have been added where necessary.
  • All new and existing tests are passing.

🐤

@github-actions
Copy link

size-limit report 📦

Path Size
dist/index.js 1.04 MB (+0.01% 🔺)
dist/index.cjs 1.04 MB (+0.01% 🔺)

@angeloashmore angeloashmore merged commit 3854af9 into main Feb 22, 2022
@angeloashmore angeloashmore deleted the aa/integration-field-catalogs branch February 22, 2022 04:29
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

Successfully merging this pull request may close these issues.

None yet

1 participant