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

Incorrect output for Generic with UnionType #3

Closed
kanitw opened this issue Jun 11, 2017 · 4 comments
Closed

Incorrect output for Generic with UnionType #3

kanitw opened this issue Jun 11, 2017 · 4 comments

Comments

@kanitw
Copy link
Member

kanitw commented Jun 11, 2017

export type Condition<T> = {
  selection: LogicalOperand<string>;
} & T;

Condition<FieldDef|ValueDef> only has property selection but no properties from FieldDef and ValueDef.

See vega/vega-lite@06cc8dc in vega/vega-lite#1980.

Note that this is no longer a blocking issue since I redeclare this using Condition<FieldDef> | Condition<ValueDef> which is a better declaration anyway.

(I'm just filing the bug here so we are aware of this bug.)

@domoritz
Copy link
Member

It works for me

export interface LogicalOperand<T> {
    foo: T;
}

export type Condition<T> = {
  selection: LogicalOperand<string>;
} & T;

export interface MyObject {
    bar: number;
}

export type MyType = Condition<MyObject>;
{
  "$ref": "#/definitions/MyType",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "Condition<MyObject>": {
      "additionalProperties": false,
      "properties": {
        "bar": {
          "type": "number"
        },
        "selection": {
          "$ref": "#/definitions/LogicalOperand<string>"
        }
      },
      "required": [
        "bar",
        "selection"
      ],
      "type": "object"
    },
    "LogicalOperand<string>": {
      "additionalProperties": false,
      "properties": {
        "foo": {
          "type": "string"
        }
      },
      "required": [
        "foo"
      ],
      "type": "object"
    },
    "MyObject": {
      "additionalProperties": false,
      "properties": {
        "bar": {
          "type": "number"
        }
      },
      "required": [
        "bar"
      ],
      "type": "object"
    },
    "MyType": {
      "$ref": "#/definitions/Condition<MyObject>"
    }
  }
}

@kanitw
Copy link
Member Author

kanitw commented Jun 11, 2017

export type MyType = Condition;

This doesn't have a union type inside Condition.

Try export type MyType = Condition<MyObject|TheirObject>; ?

@domoritz
Copy link
Member

export type Condition<T> = {
  selection: T;
};

export interface A {
    foo: number;
    bar: number;
}

export interface B {
    bar: number;
    baz: number;
}

export type MyType = Condition<A | B>;
{
  "$ref": "#/definitions/MyType",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {
    "A": {
      "additionalProperties": false,
      "properties": {
        "bar": {
          "type": "number"
        },
        "foo": {
          "type": "number"
        }
      },
      "required": [
        "foo",
        "bar"
      ],
      "type": "object"
    },
    "B": {
      "additionalProperties": false,
      "properties": {
        "bar": {
          "type": "number"
        },
        "baz": {
          "type": "number"
        }
      },
      "required": [
        "bar",
        "baz"
      ],
      "type": "object"
    },
    "Condition<(A|B)>": {
      "additionalProperties": false,
      "properties": {
        "selection": {
          "anyOf": [
            {
              "$ref": "#/definitions/A"
            },
            {
              "$ref": "#/definitions/B"
            }
          ]
        }
      },
      "required": [
        "selection"
      ],
      "type": "object"
    },
    "MyType": {
      "$ref": "#/definitions/Condition<(A|B)>"
    }
  }
}

@domoritz
Copy link
Member

See last comment. This works now.

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

No branches or pull requests

2 participants