{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/flow/issues/1478","repository_url":"https://api.github.com/repos/facebook/flow","labels_url":"https://api.github.com/repos/facebook/flow/issues/1478/labels{/name}","comments_url":"https://api.github.com/repos/facebook/flow/issues/1478/comments","events_url":"https://api.github.com/repos/facebook/flow/issues/1478/events","html_url":"https://github.com/facebook/flow/issues/1478","id":137490051,"number":1478,"title":"Deliberately incompatible types","user":{"login":"sgentle","id":441426,"avatar_url":"https://avatars.githubusercontent.com/u/441426?v=3","gravatar_id":"","url":"https://api.github.com/users/sgentle","html_url":"https://github.com/sgentle","followers_url":"https://api.github.com/users/sgentle/followers","following_url":"https://api.github.com/users/sgentle/following{/other_user}","gists_url":"https://api.github.com/users/sgentle/gists{/gist_id}","starred_url":"https://api.github.com/users/sgentle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sgentle/subscriptions","organizations_url":"https://api.github.com/users/sgentle/orgs","repos_url":"https://api.github.com/users/sgentle/repos","events_url":"https://api.github.com/users/sgentle/events{/privacy}","received_events_url":"https://api.github.com/users/sgentle/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-01T06:53:55Z","updated_at":"2016-03-01T19:51:40Z","closed_at":null,"body":"Hi,\r\n\r\nI'd like to use types for something like the following:\r\n\r\n```javascript\r\ntype SafeString = string;\r\ntype UnsafeString = string;\r\n\r\nfunction getUserInput(): UnsafeString {\r\n  return document.querySelector('#input').value;\r\n}\r\nfunction showValue(val: SafeString) {\r\n  document.querySelector('#output').innerHTML += 'your value is ' + val + '<br>';\r\n}\r\nshowValue(getUserInput());\r\n```\r\n\r\nThat would currently pass, but I'd like the type system to catch this case (and others where I'm deliberately making a distinction between otherwise identical type aliases - UTC timestamps vs local timestamps for example).\r\n\r\nThe closest thing I have figured out is this:\r\n\r\n```javascript\r\ndeclare class Unsafe {};\r\ntype SafeString = string;\r\ntype UnsafeString = (string | Unsafe);\r\n\r\nfunction sanitize(str: UnsafeString): SafeString {\r\n  return ((str: any): SafeString);\r\n}\r\n```\r\n\r\nBut it's a little bit gross. I can't combine `UnsafeString`s and I have to make fake classes. It would be nicer if I could make subtypes of primitive types, or somehow define a type as being a special alias that requires an explicit cast.\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/facebook/flow/issues/comments/190874115","html_url":"https://github.com/facebook/flow/issues/1478#issuecomment-190874115","issue_url":"https://api.github.com/repos/facebook/flow/issues/1478","id":190874115,"user":{"login":"samwgoldman","id":254842,"avatar_url":"https://avatars.githubusercontent.com/u/254842?v=3","gravatar_id":"","url":"https://api.github.com/users/samwgoldman","html_url":"https://github.com/samwgoldman","followers_url":"https://api.github.com/users/samwgoldman/followers","following_url":"https://api.github.com/users/samwgoldman/following{/other_user}","gists_url":"https://api.github.com/users/samwgoldman/gists{/gist_id}","starred_url":"https://api.github.com/users/samwgoldman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samwgoldman/subscriptions","organizations_url":"https://api.github.com/users/samwgoldman/orgs","repos_url":"https://api.github.com/users/samwgoldman/repos","events_url":"https://api.github.com/users/samwgoldman/events{/privacy}","received_events_url":"https://api.github.com/users/samwgoldman/received_events","type":"User","site_admin":false},"created_at":"2016-03-01T19:51:40Z","updated_at":"2016-03-01T19:51:40Z","body":"I think this is a great idea. A good amount of discussion has already happened in #465."}}