{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9916","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9916/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9916/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9916/events","html_url":"https://github.com/Microsoft/TypeScript/issues/9916","id":167212008,"number":9916,"title":"Proposal: Union types should emit metadata arrays","user":{"login":"Neme","id":1364632,"avatar_url":"https://avatars.githubusercontent.com/u/1364632?v=3","gravatar_id":"","url":"https://api.github.com/users/Neme","html_url":"https://github.com/Neme","followers_url":"https://api.github.com/users/Neme/followers","following_url":"https://api.github.com/users/Neme/following{/other_user}","gists_url":"https://api.github.com/users/Neme/gists{/gist_id}","starred_url":"https://api.github.com/users/Neme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Neme/subscriptions","organizations_url":"https://api.github.com/users/Neme/orgs","repos_url":"https://api.github.com/users/Neme/repos","events_url":"https://api.github.com/users/Neme/events{/privacy}","received_events_url":"https://api.github.com/users/Neme/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Duplicate","name":"Duplicate","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-07-24T01:32:33Z","updated_at":"2016-07-24T03:02:54Z","closed_at":null,"body":"# Problem\r\n\r\nCurrently, metadata type information is not emitted on union types.  When you try to get metadata type information of union types you always get an **Object**.\r\nReturning an array of types would be more useful.\r\n\r\n# Proposal\r\n\r\nUnion types should emit metadata array.\r\n\r\n# Examples\r\n\r\n## Union types\r\n\r\n```ts\r\nfunction Decorator(constructor: Function) {}\r\n\r\n@Decorator\r\nclass Foo {\r\n    constructor(param: number | string) {}\r\n}\r\n```\r\n\r\n_~>Compiled_\r\n\r\n**Currently**\r\n```js\r\nFoo = __decorate([\r\n        Decorator, \r\n        __metadata('design:paramtypes', [Object])\r\n    ], Foo);\r\n```\r\n\r\n**Proposal**\r\n```js\r\nFoo = __decorate([\r\n        Decorator, \r\n        __metadata('design:paramtypes', [[Number, String]])\r\n    ], Foo);\r\n```\r\n\r\n## String Literal Types\r\n\r\n```ts\r\n\r\nfunction Decorator(constructor: Function) { }\r\n\r\n@Decorator\r\nclass Foo {\r\n    constructor(param: 'North' | 'East' | 'South' | 'West') { }\r\n}\r\n```\r\n\r\n_~>Compiled_\r\n\r\n**Currently**\r\n```js\r\nFoo = __decorate([\r\n        Decorator, \r\n        __metadata('design:paramtypes', [Object])\r\n    ], Foo);\r\n```\r\n\r\n**Proposal**\r\n```js\r\nFoo = __decorate([\r\n        Decorator, \r\n        __metadata('design:paramtypes', [[ 'North', 'East', 'South', 'West']])\r\n    ], Foo);\r\n```\r\n\r\n## Null\r\n```ts\r\nfunction Decorator(constructor: Function) { }\r\n\r\n@Decorator\r\nclass Foo {\r\n    constructor(param: string | null) { }\r\n}\r\n```\r\n\r\n_~>Compiled_\r\n\r\n**Currently**\r\n```js\r\nFoo = __decorate([\r\n        Decorator, \r\n        __metadata('design:paramtypes', [Object])\r\n    ], Foo);\r\n```\r\n\r\n**Proposal**\r\n```js\r\nFoo = __decorate([\r\n        Decorator, \r\n        __metadata('design:paramtypes', [[String,  null]])\r\n    ], Foo);\r\n```\r\n## Undefined\r\n```ts\r\nfunction Decorator(constructor: Function) { }\r\n\r\n@Decorator\r\nclass Foo {\r\n    constructor(param: string | undefined) { }\r\n}\r\n```\r\n\r\n_~>Compiled_\r\n\r\n**Currently**\r\n```js\r\nFoo = __decorate([\r\n        Decorator, \r\n        __metadata('design:paramtypes', [Object])\r\n    ], Foo);\r\n```\r\n\r\n**Proposal**\r\n```js\r\nFoo = __decorate([\r\n        Decorator, \r\n        __metadata('design:paramtypes', [String])\r\n    ], Foo);\r\n```\r\n\r\n# Use case\r\n\r\nFor example, when you want the type information to generate your database tables.\r\n```ts\r\nclass Age {\r\n\r\n    @Attribute\r\n    public name :string;   // VARCHAR\r\n     \r\n\r\n    @Attribute\r\n    public gender : ['male', 'female'];   // ENUM('male', 'female')\r\n}\r\n```\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/234754127","html_url":"https://github.com/Microsoft/TypeScript/issues/9916#issuecomment-234754127","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9916","id":234754127,"user":{"login":"Neme","id":1364632,"avatar_url":"https://avatars.githubusercontent.com/u/1364632?v=3","gravatar_id":"","url":"https://api.github.com/users/Neme","html_url":"https://github.com/Neme","followers_url":"https://api.github.com/users/Neme/followers","following_url":"https://api.github.com/users/Neme/following{/other_user}","gists_url":"https://api.github.com/users/Neme/gists{/gist_id}","starred_url":"https://api.github.com/users/Neme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Neme/subscriptions","organizations_url":"https://api.github.com/users/Neme/orgs","repos_url":"https://api.github.com/users/Neme/repos","events_url":"https://api.github.com/users/Neme/events{/privacy}","received_events_url":"https://api.github.com/users/Neme/received_events","type":"User","site_admin":false},"created_at":"2016-07-24T03:02:54Z","updated_at":"2016-07-24T03:02:54Z","body":"I would love to see a feature like #3015 in typescript.\r\nThis would give us the opportunity for so many things.\r\n\r\nIf the .js file gets to big why don't support a specific metafile like [https://github.com/artifacthealth/tsreflect-compiler](here) natively.\r\nA compiler option (like --metaFile) would generete such a .json file."}}
{"actor":{"display_login":"Neme"}}