Skip to content

Do not report errors of implicit any during contexual type checking of binding pattern element #8241

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 4 commits into from
Aug 18, 2016

Conversation

sheetalkamat
Copy link
Member

Fixes #8229

// @noimplicitany: true
let [a, b, c] = [1, 2, 3]; // no error
let [a1 = 10, b1 = 10, c1 = 10] = [1, 2, 3]; // no error
let [a2 = undefined, b2 = undefined, c2 = undefined] = [1, 2, 3]; // no error
Copy link
Contributor

Choose a reason for hiding this comment

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

Should having default initializer be "undefined" get an noImplicitAny error? as it is similar to doing this
var x = undefined or function foo(x=undefined) {} in both case, the compiler will give an error

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really. It is different than that because destructuring(here a2) gets the typing through rhs (here as number because of rhs assignment of [1,2,3])

Copy link
Contributor

Choose a reason for hiding this comment

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

got it! Thanks. Though, in below case

let [a=undefined] = [];

Should it be an error? (would you add the test in as well?)

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. 👍 After adding the tests

@mhegazy
Copy link
Contributor

mhegazy commented Apr 21, 2016

👍

@thebanjomatic
Copy link

👍

@ahejlsberg
Copy link
Member

I'm not crazy about the extra reportErrors parameter. Can't you just know from the binding element and its context whether to report the implicit any error?

@sheetalkamat
Copy link
Member Author

@ahejlsberg Do you have anything in mind because apart from combining options includePatternInBindingType and reportErrors there is no way of where you are as both are called during typeCheck. Didn't want to combine two flags passed in to the function as they represent two different things and its more readable this way instead.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 15, 2016

@sheetalkamat can you refresh the PR?

@mhegazy mhegazy merged commit a621c09 into master Aug 18, 2016
@mhegazy mhegazy deleted the noImplicitAnyDestructuring branch August 18, 2016 23:18
@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.

6 participants