{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3704","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3704/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3704/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3704/events","html_url":"https://github.com/Microsoft/TypeScript/issues/3704","id":92528216,"number":3704,"title":"Redundant lines of code generated from constructors?","user":{"login":"MaikelChan","id":7031754,"avatar_url":"https://avatars.githubusercontent.com/u/7031754?v=3","gravatar_id":"","url":"https://api.github.com/users/MaikelChan","html_url":"https://github.com/MaikelChan","followers_url":"https://api.github.com/users/MaikelChan/followers","following_url":"https://api.github.com/users/MaikelChan/following{/other_user}","gists_url":"https://api.github.com/users/MaikelChan/gists{/gist_id}","starred_url":"https://api.github.com/users/MaikelChan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaikelChan/subscriptions","organizations_url":"https://api.github.com/users/MaikelChan/orgs","repos_url":"https://api.github.com/users/MaikelChan/repos","events_url":"https://api.github.com/users/MaikelChan/events{/privacy}","received_events_url":"https://api.github.com/users/MaikelChan/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Question","name":"Question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-07-02T02:12:51Z","updated_at":"2015-07-05T20:45:28Z","closed_at":null,"body":"Hello everyone.\r\n\r\nI'm learning TypeScript and I noticed some weird behaviour. I don't know if it's intentional or not and I didn't find answers because I don't know exactly how to describe the issue since English is not my main language. But let me show you an example:\r\n\r\nI have this class:\r\n\r\n```typescript\r\nclass Vector2D {\r\n\r\n\tX: number;\r\n\tY: number;\r\n\r\n\tconstructor();\r\n    constructor(X: number, Y: number);\r\n    constructor(X?: number, Y?: number) {\r\n        this.X = X || 0;\r\n        this.Y = Y || 0;\r\n    }\r\n}\r\n```\r\nAnd it generates this javascript code, which is fine:\r\n\r\n```typescript\r\nvar Vector2D = (function () {\r\n    function Vector2D(X, Y) {\r\n        this.X = X || 0;\r\n        this.Y = Y || 0;\r\n    }\r\n    return Vector2D;\r\n})();\r\n```\r\n\r\nHowever, from what I understand, there is a shorter way to write that code that should do exactly the same:\r\n\r\n```typescript\r\nclass Vector2D {\r\n\r\n    constructor();\r\n    constructor(X: number, Y: number);\r\n    constructor(public X?: number, public Y?: number) {\r\n        this.X = X || 0;\r\n        this.Y = Y || 0;\r\n    }\r\n}\r\n```\r\n\r\nAnd it generates this Javascript code:\r\n\r\n```typescript\r\nvar Vector2D = (function () {\r\n    function Vector2D(X, Y) {\r\n        this.X = X;\r\n        this.Y = Y;\r\n        this.X = X || 0;\r\n        this.Y = Y || 0;\r\n    }\r\n    return Vector2D;\r\n})();\r\n```\r\n\r\nIt does the same, but notice those two extra lines that have no purpose. So I don't know if I'm doing something wrong, or if this is a normal behaviour or some kind bug.\r\n\r\nThanks for your attention. Greetings! :)"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/118666724","html_url":"https://github.com/Microsoft/TypeScript/issues/3704#issuecomment-118666724","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3704","id":118666724,"user":{"login":"doskallemaskin","id":4872503,"avatar_url":"https://avatars.githubusercontent.com/u/4872503?v=3","gravatar_id":"","url":"https://api.github.com/users/doskallemaskin","html_url":"https://github.com/doskallemaskin","followers_url":"https://api.github.com/users/doskallemaskin/followers","following_url":"https://api.github.com/users/doskallemaskin/following{/other_user}","gists_url":"https://api.github.com/users/doskallemaskin/gists{/gist_id}","starred_url":"https://api.github.com/users/doskallemaskin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doskallemaskin/subscriptions","organizations_url":"https://api.github.com/users/doskallemaskin/orgs","repos_url":"https://api.github.com/users/doskallemaskin/repos","events_url":"https://api.github.com/users/doskallemaskin/events{/privacy}","received_events_url":"https://api.github.com/users/doskallemaskin/received_events","type":"User","site_admin":false},"created_at":"2015-07-05T20:45:28Z","updated_at":"2015-07-05T20:45:28Z","body":"I'm not sure if it's a wierd behaviour or if you're just not using default parameters as intended. For instance why don't you just do this:\r\n\r\n\r\n    class Vector2D {\r\n        X: number;\r\n        Y: number;\r\n        constructor(X:number = 0, Y:number = 0) {\r\n            this.X = X;\r\n            this.Y = Y;\r\n        }\r\n    }\r\n\r\nthis should cover all the constructors you asked for without overloading it.\r\n\r\nor \r\n\r\n    class Vector2D {\r\n        constructor(public X:number = 0, public y:number = 0) {\r\n        }\r\n    }"}}