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

Revamp Enum type generation. #43

Merged
merged 1 commit into from
Oct 25, 2019
Merged

Revamp Enum type generation. #43

merged 1 commit into from
Oct 25, 2019

Conversation

Eyas
Copy link
Collaborator

@Eyas Eyas commented Oct 25, 2019

Inspired by #40 and, to an extent, by #37:

Given an object of name 'Foo' which has enum types, we now allow the
name 'Foo' itself to both refer to the total type (as currently), and
the prefix for the specific enum values.

So all of let x: Foo;, let x = Foo.SOME_VALUE, as well as
let.x: Foo = Foo.SOME_VALUE are valid.

Deprecate FooEnum, introducing instead temporary aliases:
export const FooEnum = Foo; and
export type FooEnum = Foo;.

We'll remove these before 1.0.

Given an object of name 'Foo' which has enum types, we now allow the
name 'Foo' itself to both refer to the total type (as currently), and
the prefix for the specific enum values.

So all of `let x: Foo;`, `let x = Foo.SOME_VALUE`, as well as
`let.x: Foo = Foo.SOME_VALUE` are valid.

Deprecate `FooEnum`, introducing instead temporary aliases:
`export const FooEnum = Foo;` and
`export type FooEnum = Foo;`.

We'll remove these before 1.0.
@Eyas
Copy link
Collaborator Author

Eyas commented Oct 25, 2019

See, for example, the Audience type (which is both an Enum and has member properties):

Generated TypeScript:

type AudienceBase = IntangibleBase & {
    /** The target group associated with a given audience (e.g. veterans, car owners, musicians, etc.). */
    "audienceType"?: Text | Text[];
    /** The geographic area associated with the audience. */
    "geographicArea"?: AdministrativeArea | AdministrativeArea[];
};
/** Intended audience for an item, i.e. the group for whom the item was created. */
export type Audience = "http://schema.org/Researcher" | (({
    "@type": "Audience";
} & AudienceBase) | (BusinessAudience | EducationalAudience | MedicalAudience | PeopleAudience));
export const Audience = {
    /** Researchers. */
    Researcher: ("http://schema.org/Researcher" as const)
};
/** @deprecated Use Audience as a variable instead. */
export const AudienceEnum = Audience;
/** @deprecated Use Audience as a type instead. */
export type AudienceEnum = Audience;

Resulting package .d.ts:

declare type AudienceBase = IntangibleBase & {
    /** The target group associated with a given audience (e.g. veterans, car owners, musicians, etc.). */
    "audienceType"?: Text | Text[];
    /** The geographic area associated with the audience. */
    "geographicArea"?: AdministrativeArea | AdministrativeArea[];
};
/** Intended audience for an item, i.e. the group for whom the item was created. */
export declare type Audience = "http://schema.org/Researcher" | (({
    "@type": "Audience";
} & AudienceBase) | (BusinessAudience | EducationalAudience | MedicalAudience | PeopleAudience));
export declare const Audience: {
    /** Researchers. */
    Researcher: "http://schema.org/Researcher";
};
/** @deprecated Use Audience as a variable instead. */
export declare const AudienceEnum: {
    /** Researchers. */
    Researcher: "http://schema.org/Researcher";
};
/** @deprecated Use Audience as a type instead. */
export declare type AudienceEnum = Audience;

Resulting package .js:

exports.Audience = {
    /** Researchers. */
    Researcher: "http://schema.org/Researcher"
};
/** @deprecated Use Audience as a variable instead. */
exports.AudienceEnum = exports.Audience;

@Eyas Eyas merged commit 64fcfb0 into google:master Oct 25, 2019
@Eyas Eyas deleted the cleaner-enums branch January 29, 2020 22:07
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