{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9312","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9312/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9312/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9312/events","html_url":"https://github.com/Microsoft/TypeScript/issues/9312","id":161701420,"number":9312,"title":"Missing type-check on explicit cast?","user":{"login":"mindplay-dk","id":103348,"avatar_url":"https://avatars.githubusercontent.com/u/103348?v=3","gravatar_id":"","url":"https://api.github.com/users/mindplay-dk","html_url":"https://github.com/mindplay-dk","followers_url":"https://api.github.com/users/mindplay-dk/followers","following_url":"https://api.github.com/users/mindplay-dk/following{/other_user}","gists_url":"https://api.github.com/users/mindplay-dk/gists{/gist_id}","starred_url":"https://api.github.com/users/mindplay-dk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindplay-dk/subscriptions","organizations_url":"https://api.github.com/users/mindplay-dk/orgs","repos_url":"https://api.github.com/users/mindplay-dk/repos","events_url":"https://api.github.com/users/mindplay-dk/events{/privacy}","received_events_url":"https://api.github.com/users/mindplay-dk/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Working%20as%20Intended","name":"Working as Intended","color":"fbca04"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-06-22T14:41:07Z","updated_at":"2016-06-30T16:36:05Z","closed_at":"2016-06-28T07:30:58Z","body":"**TypeScript Version:** \r\n\r\n1.8.10\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface Foo {\r\n\tfoo()\r\n\tbar()\r\n}\r\n\r\n// does NOT error:\r\n\r\nvar a = <Foo> {\r\n\tfoo() {}\r\n\t// missing bar() - no error!\r\n}\r\n\r\nvar b = {\r\n\tfoo() {}\r\n\t// missing bar() - no error!\r\n} as Foo\r\n\r\n// errors: (b not assignable to type Foo)\r\n\r\nvar c: Foo = {\r\n\tfoo() {}\r\n\t// missing bar() - error\r\n}\r\n\r\nfunction d() : Foo {\r\n\treturn {\r\n\t\tfoo() {}\r\n\t\t// missing bar() - error\r\n\t}\r\n}\r\n```\r\n\r\nIn the two first cases, the shape (and inferred type) of the anonymous object are missing a method and clearly are not assignable to `Foo` - I was expecting an error message.\r\n\r\nI don't fully understand why assignment to a var vs assignment to an explicitly typed var or return-type would behave inconsistently in terms of type-checking.\r\n\r\nDidn't it use to be that you had to do something like `var a = <Foo> <any> { .. }`, e.g. you had to explicitly cast the inferred object type/shape to `any` before you'd be allowed to do an unsafe type-cast?\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/229714891","html_url":"https://github.com/Microsoft/TypeScript/issues/9312#issuecomment-229714891","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/9312","id":229714891,"user":{"login":"mindplay-dk","id":103348,"avatar_url":"https://avatars.githubusercontent.com/u/103348?v=3","gravatar_id":"","url":"https://api.github.com/users/mindplay-dk","html_url":"https://github.com/mindplay-dk","followers_url":"https://api.github.com/users/mindplay-dk/followers","following_url":"https://api.github.com/users/mindplay-dk/following{/other_user}","gists_url":"https://api.github.com/users/mindplay-dk/gists{/gist_id}","starred_url":"https://api.github.com/users/mindplay-dk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mindplay-dk/subscriptions","organizations_url":"https://api.github.com/users/mindplay-dk/orgs","repos_url":"https://api.github.com/users/mindplay-dk/repos","events_url":"https://api.github.com/users/mindplay-dk/events{/privacy}","received_events_url":"https://api.github.com/users/mindplay-dk/received_events","type":"User","site_admin":false},"created_at":"2016-06-30T16:36:05Z","updated_at":"2016-06-30T16:36:05Z","body":"That all makes sense, and I don't think we fundamentally disagree - I'm only talking about the the case where a type-cast is being applied directly to an object literal, because that's kind of like an informal/dynamic constructor, and it's a common JS pattern, constructing something with a known shape but with no formal constructor.\r\n\r\nAnyhow, yeah, maybe what I'm describing isn't actually a type-cast at all - maybe it's a different feature altogether, something that shouldn't get mixed up with type-casts... it just felt like the natural thing to reach for, and it was kind of surprising to me when it didn't work - but maybe that's just me ;-)\r\n"}}
{"actor":{"display_login":"mindplay-dk"}}