Created
June 30, 2021 21:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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