{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/10504","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/10504/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/10504/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/10504/events","html_url":"https://github.com/PowerShell/PowerShell/issues/10504","id":491226899,"node_id":"MDU6SXNzdWU0OTEyMjY4OTk=","number":10504,"title":"Feature Request: -Is operator: suppress \"Cannot convert\"error","user":{"login":"iRon7","id":8080834,"node_id":"MDQ6VXNlcjgwODA4MzQ=","avatar_url":"https://avatars3.githubusercontent.com/u/8080834?v=4","gravatar_id":"","url":"https://api.github.com/users/iRon7","html_url":"https://github.com/iRon7","followers_url":"https://api.github.com/users/iRon7/followers","following_url":"https://api.github.com/users/iRon7/following{/other_user}","gists_url":"https://api.github.com/users/iRon7/gists{/gist_id}","starred_url":"https://api.github.com/users/iRon7/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iRon7/subscriptions","organizations_url":"https://api.github.com/users/iRon7/orgs","repos_url":"https://api.github.com/users/iRon7/repos","events_url":"https://api.github.com/users/iRon7/events{/privacy}","received_events_url":"https://api.github.com/users/iRon7/received_events","type":"User","site_admin":false},"labels":[{"id":311043050,"node_id":"MDU6TGFiZWwzMTEwNDMwNTA=","url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Issue-Enhancement","name":"Issue-Enhancement","color":"fc2929","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2019-09-09T17:28:36Z","updated_at":"2019-09-10T02:25:40Z","closed_at":null,"author_association":"NONE","body":"Suppress the error on the `-is` operator when the type is supplied as a string:\r\n\r\n`$a -is 'UnknownType'`\r\n\r\n> Cannot convert the \"UnknownType\" value of type \"System.String\" to type \"System.Type\".\r\n> At line:1 char:1\r\n> + $a -is 'UnknownType'\r\n> + ~~~~~~~~~~~~~~~~~~~~\r\n> + CategoryInfo          : NotSpecified: (:) [], RuntimeException\r\n> + FullyQualifiedErrorId : RuntimeException\r\n\r\nIf \"strict\" programming is required, the system.type (square brackets) should be used instead:\r\n\r\n`$a -is [UnknownType]`\r\n\r\n> Unable to find type [UnknownType].\r\n> At line:1 char:8\r\n> + $a -is [UnknownType]\r\n> +        ~~~~~~~~~~~~~\r\n> + CategoryInfo          : InvalidOperation: (UnknownType:TypeName) [], RuntimeException\r\n> + FullyQualifiedErrorId : TypeNotFound\r\n\r\n<sub>(Were the error is actually generated by the type casting and not the `-is`operator.)/sub>\r\n\r\nThis would allow for easier type checking on types that might not exist in certain environments (like `[semver]` that doesn't exist in Windows PowerShell, see also: Stackoverflow: [How to test a (possible) unknown type?](https://stackoverflow.com/q/57805460/1701026)\r\n\r\nBesides, I think this is more in line with the general PowerShell behavor set by the PowerShell team: [\"Type Conversion in PowerShell is, without question, one of the most useful ingredients in its \"Magic Sauce\" of administrator effectiveness.\"](https://devblogs.microsoft.com/powershell/understanding-powershells-type-conversion-magic/) and looking to other comparison operators, there aren't many operators that can produce an error.\r\n\r\nIn other words, from my perspective:\r\n`$a -is 'UnknownType'` should just return `$False` without error and `$a -isnot 'UnknownType'` should just return `$True` without error. "},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments/529740988","html_url":"https://github.com/PowerShell/PowerShell/issues/10504#issuecomment-529740988","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/10504","id":529740988,"node_id":"MDEyOklzc3VlQ29tbWVudDUyOTc0MDk4OA==","user":{"login":"SeeminglyScience","id":24977523,"node_id":"MDQ6VXNlcjI0OTc3NTIz","avatar_url":"https://avatars3.githubusercontent.com/u/24977523?v=4","gravatar_id":"","url":"https://api.github.com/users/SeeminglyScience","html_url":"https://github.com/SeeminglyScience","followers_url":"https://api.github.com/users/SeeminglyScience/followers","following_url":"https://api.github.com/users/SeeminglyScience/following{/other_user}","gists_url":"https://api.github.com/users/SeeminglyScience/gists{/gist_id}","starred_url":"https://api.github.com/users/SeeminglyScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SeeminglyScience/subscriptions","organizations_url":"https://api.github.com/users/SeeminglyScience/orgs","repos_url":"https://api.github.com/users/SeeminglyScience/repos","events_url":"https://api.github.com/users/SeeminglyScience/events{/privacy}","received_events_url":"https://api.github.com/users/SeeminglyScience/received_events","type":"User","site_admin":false},"created_at":"2019-09-10T02:25:40Z","updated_at":"2019-09-10T02:25:40Z","author_association":"CONTRIBUTOR","body":"I think this would mostly end up just making typos harder to find.  Granted that's generally speaking pretty on brand for PowerShell, but the use cases here are not as compelling as with other instances.\r\n\r\nMost of the time when you're not using a default type, you're going to be explicitly loading the assembly.  In most of the cases you aren't doing that, you probably still *need* it loaded .  In the few cases were you truly want this failure to be ignored, you're better off being slightly more explicit with something like this:\r\n\r\n```powershell\r\nif ('SomeType' -as [type] -and $var -is [SomeType]) {\r\n    return $true\r\n}\r\n```"}}
{"actor":{"display_login":"SeeminglyScience"}}