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

Relax index signature checks for type any #4074

Merged
merged 4 commits into from
Jul 30, 2015
Merged

Conversation

ahejlsberg
Copy link
Member

With this change, a type without an index signature is considered related to a type with an index signature if the type of that index signature is any. For example:

var x: { foo: number, [x: string]: any };
let y = { foo: 1, baz: 2 }; 
x = y;  // No longer an error

The assignment x = y was previously considered an error because y has no index signature. However, given that an index signature of type any doesn't actually constrain properties in the type, the assignment is now permitted.

This issue was originally reported by @joewood here.

@@ -5251,7 +5251,7 @@ namespace ts {
return indexTypesIdenticalTo(IndexKind.String, source, target);
}
let targetType = getIndexTypeOfType(target, IndexKind.String);
if (targetType) {
if (targetType && !(targetType.flags & TypeFlags.Any)) {
Copy link
Member

Choose a reason for hiding this comment

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

Use isTypeAny

Copy link
Member Author

Choose a reason for hiding this comment

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

That would just add function call and a redundant null check.

@RyanCavanaugh
Copy link
Member

👍

@ahejlsberg
Copy link
Member Author

@JsonFreeman Agreed.

@JsonFreeman
Copy link
Contributor

👍

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.

4 participants