{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1897","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1897/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1897/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1897/events","html_url":"https://github.com/Microsoft/TypeScript/issues/1897","id":56296923,"number":1897,"title":"Please provide a `json` basic type","user":{"login":"NoelAbrahams","id":1106823,"avatar_url":"https://avatars.githubusercontent.com/u/1106823?v=3","gravatar_id":"","url":"https://api.github.com/users/NoelAbrahams","html_url":"https://github.com/NoelAbrahams","followers_url":"https://api.github.com/users/NoelAbrahams/followers","following_url":"https://api.github.com/users/NoelAbrahams/following{/other_user}","gists_url":"https://api.github.com/users/NoelAbrahams/gists{/gist_id}","starred_url":"https://api.github.com/users/NoelAbrahams/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NoelAbrahams/subscriptions","organizations_url":"https://api.github.com/users/NoelAbrahams/orgs","repos_url":"https://api.github.com/users/NoelAbrahams/repos","events_url":"https://api.github.com/users/NoelAbrahams/events{/privacy}","received_events_url":"https://api.github.com/users/NoelAbrahams/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Needs%20More%20Info","name":"Needs More Info","color":"556b75"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Needs%20Proposal","name":"Needs Proposal","color":"556b75"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-02T21:37:47Z","updated_at":"2015-02-02T22:04:16Z","closed_at":null,"body":"Hi,\r\n\r\nJSON is an important data exchange format. At present there is no explicit way to annotate an object as pure JSON. We were expecting union types to solve this problem via the following:\r\n\r\n```typeScript\r\n    interface Json {\r\n        [x: string]: string|number|boolean|Date|Json|JsonArray;\r\n    }\r\n    interface JsonArray extends Array<string|number|boolean|Date|Json|JsonArray> { }\r\n```\r\n\r\nThere are currently a number of problems with this.\r\n\r\n* Contextual typing is absent in parenthetic expression #920 \r\n\r\n ```typeScript\r\n    interface Id extends Json {\r\n        id: number;\r\n    }\r\n\r\n    var z = (): Id => ({id: 'foo'}); // Error: Missing index signature\r\n ```\r\n\r\n* Contextual typing does not flow from base to subclasses #1373  \r\n\r\n```typeScript\r\nclass Bass {\r\n\t\r\n\tf(): Id{ return undefined;}\r\n}\r\n\r\n // Error: missing index signature\r\nclass Foo extends Bass {\r\n\tf() { return { id: 10 }} \r\n}\r\n```\r\n\r\n* Object literals require explicit index signatures #1889:\r\n\r\n```typeScript\r\n    interface Foo extends Json {\r\n        \r\n        foo: { val: string }; // Error: Not assignable\r\n        \r\n    }\r\n```\r\n\r\n* Other problems: \r\n\r\n ```TypeScript\r\n// Error: Missing index signature\r\nvar result: Id[] = 'a|b'.split('|').map(item => {\r\n          return { id: 0 };\r\n });\r\n ```\r\n\r\nThe first two problems look likely to be resolved, but not the last two.\r\n\r\nThis motivates the introduction of a natively supported `json` type that conforms to the [JSON spec](http://www.json.org/).\r\n\r\nIt should be possible to derive a custom JSON object from the `json` type with non of the problems above. Furthermore, since JSON is a data exchange format it should be possible to mark fields as nullable on types deriving from `json` (which would trigger a type guard).\r\n\r\nI am of course aware that this is all rather vague!"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/72547962","html_url":"https://github.com/Microsoft/TypeScript/issues/1897#issuecomment-72547962","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/1897","id":72547962,"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-02-02T22:04:16Z","updated_at":"2015-02-02T22:04:16Z","body":"For the record:\r\n\r\n* Not only is #920 likely to be resolved, it currently is in `master`.\r\n* #1373 needs a proposal first.\r\n* I don't think it's *unfeasible* for #1889 to be resolved, but it is a difficult problem."}}