{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18211","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18211/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18211/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18211/events","html_url":"https://github.com/Microsoft/TypeScript/issues/18211","id":254721516,"number":18211,"title":"Question: keys of a type which have a certain type","user":{"login":"Peter-Juhasz","id":9047283,"avatar_url":"https://avatars3.githubusercontent.com/u/9047283?v=4","gravatar_id":"","url":"https://api.github.com/users/Peter-Juhasz","html_url":"https://github.com/Peter-Juhasz","followers_url":"https://api.github.com/users/Peter-Juhasz/followers","following_url":"https://api.github.com/users/Peter-Juhasz/following{/other_user}","gists_url":"https://api.github.com/users/Peter-Juhasz/gists{/gist_id}","starred_url":"https://api.github.com/users/Peter-Juhasz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Peter-Juhasz/subscriptions","organizations_url":"https://api.github.com/users/Peter-Juhasz/orgs","repos_url":"https://api.github.com/users/Peter-Juhasz/repos","events_url":"https://api.github.com/users/Peter-Juhasz/events{/privacy}","received_events_url":"https://api.github.com/users/Peter-Juhasz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-09-01T18:42:17Z","updated_at":"2017-09-01T20:09:42Z","closed_at":null,"author_association":"NONE","body":"The type system is awesome, but I am struggling with this problem.\r\n\r\n```ts\r\nclass View<TMode> {\r\n    public sortBy(source: TModel[], property: keyof TModel): void {\r\n    }\r\n}\r\n```\r\n\r\nIs it possible to restrict the second parameter to those keys of `TModel` which type is `string`?\r\n\r\nFor example, if I have an object like this:\r\n```ts\r\n{\r\n    \"id\": 1,\r\n    \"name\": \"hello\",\r\n}\r\n```\r\n\r\nThen the only allowed key is `\"name\"`.\r\n\r\nIf not supported now,\r\n - does any workaround exists with advanced type arithmetic?\r\n - is it planned?\r\n\r\nThanks."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/326673245","html_url":"https://github.com/Microsoft/TypeScript/issues/18211#issuecomment-326673245","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/18211","id":326673245,"user":{"login":"kitsonk","id":1282577,"avatar_url":"https://avatars0.githubusercontent.com/u/1282577?v=4","gravatar_id":"","url":"https://api.github.com/users/kitsonk","html_url":"https://github.com/kitsonk","followers_url":"https://api.github.com/users/kitsonk/followers","following_url":"https://api.github.com/users/kitsonk/following{/other_user}","gists_url":"https://api.github.com/users/kitsonk/gists{/gist_id}","starred_url":"https://api.github.com/users/kitsonk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kitsonk/subscriptions","organizations_url":"https://api.github.com/users/kitsonk/orgs","repos_url":"https://api.github.com/users/kitsonk/repos","events_url":"https://api.github.com/users/kitsonk/events{/privacy}","received_events_url":"https://api.github.com/users/kitsonk/received_events","type":"User","site_admin":false},"created_at":"2017-09-01T20:09:42Z","updated_at":"2017-09-01T20:09:42Z","author_association":"CONTRIBUTOR","body":"This is not a support forum.\r\n\r\nQuestions should be asked at [StackOverflow](http://stackoverflow.com/questions/ask?tags=typescript) or on [Gitter.im](https://gitter.im/Microsoft/TypeScript).\r\n\r\nAlso, it seems to [work](http://www.typescriptlang.org/play/#src=class%20View%3CT%3E%20%7B%0A%20%20%20%20public%20sortBy(source%3A%20T%5B%5D%2C%20property%3A%20keyof%20T)%3A%20void%20%7B%0A%20%20%20%20%7D%0A%7D%0A%0Aconst%20v%20%3D%20new%20View%3C%7B%20id%3A%20number%3B%20name%3A%20string%3B%20%7D%3E()%3B%0A%0Av.sortBy(%5B%5D%2C%20'name')%3B%0A) as you would expect, unless I am missing something:\r\n\r\n```ts\r\nclass View<T> {\r\n    public sortBy(source: T[], property: keyof T): void {\r\n    }\r\n}\r\n\r\nconst v = new View<{ id: number; name: string; }>();\r\n\r\nv.sortBy([], 'name');\r\n```\r\n"}}
{"actor":{"display_login":"kitsonk"}}