Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angeloashmore/266c66be333a533ee0009c99d85885b4 to your computer and use it in GitHub Desktop.
Save angeloashmore/266c66be333a533ee0009c99d85885b4 to your computer and use it in GitHub Desktop.
Takes a record of fields and ensures only one instance of a field value type exists.
// Takes a record of fields and ensures only one instance of a field value type exists.
// See: @prismicio/types
type WithSingletonField<
Fields extends Record<string, CustomTypeField>,
FieldType extends CustomTypeField,
FieldName extends string,
> = {
[P in keyof Fields as Fields[P] extends FieldType
? P extends FieldName
? P
: never
: P]: Fields[P] extends FieldType
? P extends FieldName
? FieldType
: never
: Fields[P];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment