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 computed properties in destructuring, treat computed properties… #5535

Merged
merged 3 commits into from
Nov 10, 2015

Conversation

vladima
Copy link
Contributor

@vladima vladima commented Nov 4, 2015

… with literal expressions similar to literal named properties. Fixes #4917

… with literal expressions similar to literal named properties

({[foo2()]: bar3} = {bar: "bar"});
~~~
!!! error TS2353: Object literal may only specify known properties, and 'bar' does not exist in type '{}'.
Copy link
Member

Choose a reason for hiding this comment

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

These seem suboptimal.

Maybe we should introduce a rule that if there are dynamically named entities in a contextual type, then we don't perform the strict checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would disagree with that and would rather be more pessimistic. Requesting opinions of @ahejlsberg, @mhegazy and @RyanCavanaugh.

Copy link
Member

Choose a reason for hiding this comment

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

Ultimately, I don't really care enough because I don't know who is going to use this.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @DanielRosenwasser here. If the contextual type has computed property names it seems strange to restrict the source to only declared properties (which is practically guaranteed to not include the computed property). We should only perform the excess property check when there are no unknowns on the target side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will relax the rule

@DanielRosenwasser
Copy link
Member

👍

@vladima
Copy link
Contributor Author

vladima commented Nov 9, 2015

this PR should also cover #4653

@vladima
Copy link
Contributor Author

vladima commented Nov 10, 2015

@mhegazy can you please check this PR?

return declaration.name && isDynamicName(declaration.name);
}

export function isDynamicName(name: DeclarationName): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

i find the name a bit vague.

@mhegazy
Copy link
Contributor

mhegazy commented Nov 10, 2015

👍

vladima added a commit that referenced this pull request Nov 10, 2015
…ringPR

allow computed properties in destructuring, treat computed properties…
@vladima vladima merged commit 072e938 into master Nov 10, 2015
@vladima vladima deleted the computedPropertiesInDestructuringPR branch November 10, 2015 21:11
@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