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

Allow to override a property type #1295

Merged
merged 7 commits into from
Jan 26, 2022
Merged

Allow to override a property type #1295

merged 7 commits into from
Jan 26, 2022

Conversation

delvedor
Copy link
Member

As titled.

Related: #1283

Copy link
Member

@swallez swallez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of OverloadOf<> is to have two almost identical structures where the only difference is the optionality of fields. This allows code generators to produce converters between a type and its overloaded sibling.

Allowing type changes basically prevents generation of these converters and makes this behavior useless.

I may be missing something though, as I haven't spent time on this and the Java client doesn't yet have these converters.

Copy link
Contributor

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor but don't know if there are consequences for strongly typed langs. Deferring to @swallez here :)

Copy link
Contributor

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

// but let's address it when it will happen
if (!deepEqual(readProperty.type, property.type)) {

if (property.type.kind === 'union_of' && property.type.items.some(contains(readProperty.type))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this allow arbitrary unions as long as one of its members is the read property, e.g. ReadFoo | Bar?

Should we rather test that all unwrap'ed union items are readProperty.type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows the read property to be a single element of the parent union.
Eg:

export class Foo {
  bar: string | string[]
}

export class FooRead implements OverloadOf<Foo> {
  bar: string[]
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, I didn't read the relation check in the right direction.

Copy link
Member

@swallez swallez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants