{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8085","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8085/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8085/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/8085/events","html_url":"https://github.com/Microsoft/TypeScript/issues/8085","id":148283553,"number":8085,"title":"[Suggestion] Provide a way to opt-out strict object literal check for a specific property","user":{"login":"duanyao","id":1684137,"avatar_url":"https://avatars.githubusercontent.com/u/1684137?v=3","gravatar_id":"","url":"https://api.github.com/users/duanyao","html_url":"https://github.com/duanyao","followers_url":"https://api.github.com/users/duanyao/followers","following_url":"https://api.github.com/users/duanyao/following{/other_user}","gists_url":"https://api.github.com/users/duanyao/gists{/gist_id}","starred_url":"https://api.github.com/users/duanyao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duanyao/subscriptions","organizations_url":"https://api.github.com/users/duanyao/orgs","repos_url":"https://api.github.com/users/duanyao/repos","events_url":"https://api.github.com/users/duanyao/events{/privacy}","received_events_url":"https://api.github.com/users/duanyao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-14T08:04:00Z","updated_at":"2016-04-14T08:04:00Z","closed_at":null,"body":"<!--\r\nThank you for contributing to TypeScript! Please review this checklist\r\n       before submitting your issue.\r\n[ ] Many common issues and suggestions are addressed in the FAQ\r\n     https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n[ ] Search for duplicates before logging new issues\r\n    https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93&q=is%3Aissue\r\n[ ] Questions are best asked and answered at Stack Overflow\r\n    http://stackoverflow.com/questions/tagged/typescript\r\n\r\nFor bug reports, please include the information below.\r\n__________________________________________________________ -->\r\n\r\n**TypeScript Version:** \r\n\r\n1.8.10\r\n\r\n## Problem\r\n\r\nSometimes we want to opt-out strict object literal check for a specific property. Some types have large amount or even unlimited number of properties, and we only want to model the most frequently used ones. However when we do use an unmodeled property in an object literal, the compiler  complains. E.g.:\r\n\r\n```ts\r\ninterface AttrBag {\r\n  id?: string;\r\n  style?: string;\r\n  title?: string;\r\n  'class'?: string;\r\n}\r\n\r\nfunction setAttrs(el: Element, attrs: AttrBag) {\r\n  //...\r\n}\r\n\r\nsetAttrs(document.createElement('a'), {\r\n  title: 'foo', \r\n  href: 'bar', // error\r\n  'data-x': 'y', //error\r\n});\r\n```\r\n\r\n## Existing solutions\r\nExisting solutions have some limitations:\r\n\r\n* Add a type assertion for the object literal. This turns off object literal check entirely, which is undesirable, e.g.:\r\n\r\n```ts\r\nsetAttrs(document.createElement('a'), {\r\n  titile: 'foo', // typo, but no error\r\n  href: 'bar',\r\n  'data-x': 'y',\r\n} as AttrBag);\r\n```\r\n\r\n* Augument the interface for all used properties. This is heavy weight for infrequently used properties; and more importantly, the effect is usually global and can't be undone in a specific source file.\r\n\r\n## Proposed solution: \"additional property\" modifier\r\nIf a property name in a object literal is modified with `+` (\"additional property\" modifier), and it doesn't exist in the target type, compiler should skip strict object literal check for this property, and treat this property as optional. E.g.:\r\n\r\n```ts\r\nsetAttrs(document.createElement('a'), {\r\n  title: 'foo', \r\n  +href: 'bar', // OK\r\n  +'data-x': 'y', // OK\r\n});\r\n\r\n// The type of attrs is { title: string, href?: string, 'data-x'?: string }\r\nvar attrs = {\r\n  title: 'foo', \r\n  +href: 'bar',\r\n  +'data-x': 'y',\r\n};\r\n\r\nattrs = {  // OK\r\n  title: 'bar',\r\n};\r\n```\r\n"}}