Skip to content

Commit

Permalink
Ignore freshness in subtype reduction / Treat Object as {}
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Jul 13, 2015
1 parent aa26980 commit d78fa18
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3357,7 +3357,7 @@ namespace ts {
// signatures, or if the property is actually declared in the type. In a union or intersection
// type, a property is considered known if it is known in any constituent type.
function isKnownProperty(type: Type, name: string): boolean {
if (type.flags & TypeFlags.ObjectType) {
if (type.flags & TypeFlags.ObjectType && type !== globalObjectType) {
var resolved = resolveStructuredTypeMembers(type);
return !!(resolved.properties.length === 0 ||
resolved.stringIndexType ||
Expand Down Expand Up @@ -3977,7 +3977,7 @@ namespace ts {

function isSubtypeOfAny(candidate: Type, types: Type[]): boolean {
for (let type of types) {
if (candidate !== type && isTypeSubtypeOf(candidate, type)) {
if (candidate !== type && isTypeSubtypeOf(getRegularTypeOfObjectLiteral(candidate), type)) {
return true;
}
}
Expand Down

1 comment on commit d78fa18

@JsonFreeman
Copy link
Contributor

Choose a reason for hiding this comment

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

You explained the motivation for ignore freshness during subtype reduction:

It was necessary to ignore freshness because otherwise we'd infer the full precise type, which, when widened, would produce a reduced type to which the full type isn't assignable. Basically the opposite problem.

I don't understand how producing the full type makes the original type not assignable anymore. Can you give an example?

Also, please add tests for this part of the change.

Please sign in to comment.