{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2469","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2469/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2469/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2469/events","html_url":"https://github.com/Microsoft/TypeScript/issues/2469","id":63830699,"number":2469,"title":"An initialized binding element should be optional even if its parent is initialized too","user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Bug","name":"Bug","color":"e11d21"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Spec","name":"Spec","color":"207de5"}],"state":"open","locked":false,"assignee":{"login":"ahejlsberg","id":4226954,"avatar_url":"https://avatars.githubusercontent.com/u/4226954?v=3","gravatar_id":"","url":"https://api.github.com/users/ahejlsberg","html_url":"https://github.com/ahejlsberg","followers_url":"https://api.github.com/users/ahejlsberg/followers","following_url":"https://api.github.com/users/ahejlsberg/following{/other_user}","gists_url":"https://api.github.com/users/ahejlsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ahejlsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahejlsberg/subscriptions","organizations_url":"https://api.github.com/users/ahejlsberg/orgs","repos_url":"https://api.github.com/users/ahejlsberg/repos","events_url":"https://api.github.com/users/ahejlsberg/events{/privacy}","received_events_url":"https://api.github.com/users/ahejlsberg/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/8","html_url":"https://github.com/Microsoft/TypeScript/milestones/TypeScript%201.6","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/milestones/8/labels","id":900034,"number":8,"title":"TypeScript 1.6","description":"","creator":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars.githubusercontent.com/u/8000722?v=3","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"open_issues":82,"closed_issues":140,"state":"open","created_at":"2014-12-11T05:46:12Z","updated_at":"2015-07-24T00:25:30Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2015-03-23T20:57:59Z","updated_at":"2015-07-24T06:56:02Z","closed_at":null,"body":"```ts\r\nfunction foo({ x, y = {}} = { x: 0, y: {}}) {\r\n\r\n}\r\n\r\nfoo(); // Fine\r\nfoo({ x: 0, y: 0 }); // Fine\r\nfoo({ x: 0 }); // Error\r\n```\r\n\r\nThe last line should not be an error because the y property has a default initializer. The error goes away if I remove the default initializer `{ x: 0, y: {}}` on the parent.\r\n\r\nI think the rule would be that even if we get the type of a parameter / variable / binding element from an initializer, we still have to traverse the binding pattern to determine whether binding properties are optional."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/124370545","html_url":"https://github.com/Microsoft/TypeScript/issues/2469#issuecomment-124370545","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/2469","id":124370545,"user":{"login":"DanielRosenwasser","id":972891,"avatar_url":"https://avatars.githubusercontent.com/u/972891?v=3","gravatar_id":"","url":"https://api.github.com/users/DanielRosenwasser","html_url":"https://github.com/DanielRosenwasser","followers_url":"https://api.github.com/users/DanielRosenwasser/followers","following_url":"https://api.github.com/users/DanielRosenwasser/following{/other_user}","gists_url":"https://api.github.com/users/DanielRosenwasser/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielRosenwasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielRosenwasser/subscriptions","organizations_url":"https://api.github.com/users/DanielRosenwasser/orgs","repos_url":"https://api.github.com/users/DanielRosenwasser/repos","events_url":"https://api.github.com/users/DanielRosenwasser/events{/privacy}","received_events_url":"https://api.github.com/users/DanielRosenwasser/received_events","type":"User","site_admin":false},"created_at":"2015-07-24T06:56:02Z","updated_at":"2015-07-24T06:56:02Z","body":"> The order of precedence for determining the type of a variable or parameter is:\r\n\r\n> 1. Type annotation\r\n2. Initializer\r\n3. Type implied by binding pattern (if applicable)\r\n\r\n@ahejlsberg Is that actually the case? In the following example, `param` is contextually typed as a `string`, and the local variable `x` has the type `(s: string) => number`.\r\n\r\n```TypeScript\r\nvar { x = (str: string) => +str } = { x: param => param.length };\r\n```\r\n\r\nBut if we used the initializer first, wouldn't we acquire the type of `x` from the type of `x` from the RHS of the top-level initializer?\r\n\r\n>  I feel like it's not as strong an indicator of the type.\r\n\r\nYes, I see what @JsonFreeman is saying - it would be kind of ideal if the properties \"zipped up\" with respect to optionality when determining assignability. I can definitely get behind a very simple rule, but I get that there's also something to be said about flexibility here."}}