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

Support for Generic Role #164

Merged
merged 2 commits into from
Aug 17, 2021
Merged

Support for Generic Role #164

merged 2 commits into from
Aug 17, 2021

Conversation

Eyas
Copy link
Collaborator

@Eyas Eyas commented Aug 7, 2021

Supports Role fully as described in http://blog.schema.org/2014/06/introducing-role.html

Every Property can now be a Role.

This is a pretty risky change, I published schema-dts@0.11.0-beta.1 as an example.

Examples of diffs:

-declare type SchemaValue<T> = T | readonly T[];
+declare type SchemaValue<T, TProperty extends string> = T | Role<T, TProperty> | readonly (T | Role<T, TProperty>)[];
-interface RoleLeaf extends RoleBase {
-    "@type": "Role";
-}
-export declare type Role = RoleLeaf | LinkRole | OrganizationRole | PerformanceRole;
+declare type RoleLeaf<TContent, TProperty extends string> = RoleBase & {
+    "@type": "Role";
+} & {
+    [key in TProperty]: TContent;
+};
+export declare type Role<TContent = never, TProperty extends string = never> = RoleLeaf<TContent, TProperty> | LinkRole<TContent, TProperty> | OrganizationRole<TContent, TProperty> | PerformanceRole<TContent, TProperty>;
 interface PersonBase extends ThingBase {
-    "worksFor"?: SchemaValue<Organization | IdReference>;
+    "worksFor"?: SchemaValue<Organization | IdReference, "worksFor">;
 }

For schema-dts-gen, this change only becomes visible once a Role property is present. I might end up regretting this.

Fixes #143

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.

Allow Role to be used for use cases like defining dates
1 participant