Skip to content

Fix excess property check in union and intersection types #5344

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

Merged
merged 2 commits into from
Oct 20, 2015

Conversation

ahejlsberg
Copy link
Member

Fixes #5237.


var b2: Book | string = { foreward: "nope" };

var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }];
Copy link
Member

Choose a reason for hiding this comment

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

Nice test

Copy link
Member

Choose a reason for hiding this comment

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

You should have phrased that using four words

@DanielRosenwasser
Copy link
Member

LGTM

@mhegazy
Copy link
Contributor

mhegazy commented Oct 20, 2015

👍

@ahejlsberg
Copy link
Member Author

The PR modifies the rules for excess properties as follows:

A source type S is considered to have excess properties with respect to a target type T if

  • S is a fresh object literal type,
  • T is an object-like type, and
  • S has one or more properties that aren't expected in T.

A type T is said to be object-like if

  • T is an object type, or
  • T a union or intersection type containing at least one-object like type.

A property P is said to be expected in a type T if one of the following is true:

  • T is an object type and
    • T has a property with the same name as P,
    • T has a string or numeric index signature,
    • T has no properties, or
    • T is the global type 'Object'.
  • T is a union or intersection type and P is expected in at least one object-like constituent type of T.

ahejlsberg added a commit that referenced this pull request Oct 20, 2015
Fix excess property check in union and intersection types
@ahejlsberg ahejlsberg merged commit a8fa81b into master Oct 20, 2015
@mhegazy mhegazy deleted the excessPropertiesWithUnion branch October 20, 2015 21:17
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants