Title: SpyObj
Open Graph Title: SpyObj
X Title: SpyObj
Description: TypeScript Version: 2.9.2 Code interface Spy { (...params: any[]): any; identity: string; and: Function; mostRecentCall: {args: any[];}; argsForCall: any[]; } type SpyObj
Open Graph Description: TypeScript Version: 2.9.2 Code interface Spy { (...params: any[]): any; identity: string; and: Function; mostRecentCall: {args: any[];}; argsForCall: any[]; } type SpyObj
X Description: TypeScript Version: 2.9.2 Code interface Spy { (...params: any[]): any; identity: string; and: Function; mostRecentCall: {args: any[];}; argsForCall: any[]; } type SpyObj<T> = T&{ [k in k...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/25181
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SpyObj\u003cT>[keyof T] not resolving to the type SpyObj members (Jasmine typings)","articleBody":"**TypeScript Version:** 2.9.2\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface Spy {\r\n (...params: any[]): any;\r\n\r\n identity: string;\r\n and: Function;\r\n mostRecentCall: {args: any[];};\r\n argsForCall: any[];\r\n}\r\n\r\ntype SpyObj\u003cT> = T&{\r\n [k in keyof T]: Spy;\r\n}\r\n\r\ndeclare function createSpyObj\u003cT>(\r\n name: string, names: Array\u003ckeyof T>): SpyObj\u003cT>;\r\n\r\n/**\r\n * Creates a jasmine mock where every given method returns the spy object.\r\n */\r\nfunction mock\u003cT>(spyName: string, methodNames: Array\u003ckeyof T>): SpyObj\u003cT> {\r\n const spyObj = createSpyObj\u003cT>(spyName, methodNames);\r\n for (const methodName of methodNames) {\r\n spyObj[methodName].and.returnValue(1); // fails, Property 'and' does not exist on type 'SpyObj\u003cT>[keyof T]'.\r\n }\r\n return spyObj;\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\nIn TS2.8, `spyObj[methodName]` above was any, allowing `and` to be referenced on it. Ideally, this would figure out that all members of `spyObj` must at least be a `Spy`.\r\n\r\n**Actual behavior:**\r\n\r\nIn TS 2.9, there's a type `SpyObj\u003cT>[keyof T]`, but apparently it does not resolve to `Spy`?\r\n\r\n**Playground Link:** \r\n\r\nhttp://www.typescriptlang.org/play/#src=%0Ainterface%20Spy%20%7B%0A%20%20(...params%3A%20any%5B%5D)%3A%20any%3B%0A%0A%20%20identity%3A%20string%3B%0A%20%20and%3A%20Function%3B%0A%20%20mostRecentCall%3A%20%7Bargs%3A%20any%5B%5D%3B%7D%3B%0A%20%20argsForCall%3A%20any%5B%5D%3B%0A%7D%0A%0Atype%20SpyObj%3CT%3E%20%3D%20T%26%7B%0A%20%20%5Bk%20in%20keyof%20T%5D%3A%20Spy%3B%0A%7D%0A%0Adeclare%20function%20createSpyObj%3CT%3E(%0A%20%20%20%20name%3A%20string%2C%20names%3A%20Array%3Ckeyof%20T%3E)%3A%20SpyObj%3CT%3E%3B%0A%0A%2F**%0A%20*%20Creates%20a%20jasmine%20mock%20where%20every%20given%20method%20returns%20the%20spy%20object.%0A%20*%2F%0Afunction%20mock%3CT%3E(spyName%3A%20string%2C%20methodNames%3A%20Array%3Ckeyof%20T%3E)%3A%20SpyObj%3CT%3E%20%7B%0A%20%20const%20spy%20%3D%20createSpyObj%3CT%3E(spyName%2C%20methodNames)%3B%0A%20%20for%20(const%20methodName%20of%20methodNames)%20%7B%0A%20%20%20%20spy%5BmethodName%5D.and.returnValue(spy)%3B%0A%20%20%7D%0A%20%20return%20spy%3B%0A%7D%0A","author":{"url":"https://github.com/mprobst","@type":"Person","name":"mprobst"},"datePublished":"2018-06-24T14:27:24Z","url":"https://github.com/microsoft/TypeScript/issues/25181"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2178426d-9a5d-06e4-9686-eb8e35199469 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 86A8:2A7C1C:705408:93EE54:6B01A703 |
| html-safe-nonce | 9a3bbd15de6c8420a69e2e2e5bb1063306e1e6eafd971d1cc96638242861f958 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkE4OjJBN0MxQzo3MDU0MDg6OTNFRTU0OjZCMDFBNzAzIiwidmlzaXRvcl9pZCI6IjEzODI0NDA2NTAyODAxMTgwMTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d1c3e86a03721d0711deea829f7d24a249ce8fe6a3e747c804178647b2bc1590 |
| hovercard-subject-tag | issue:335183552 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/25181/issue_layout |
| twitter:image | https://opengraph.githubassets.com/de439acaf3e51b5fe9235a260406843e55c19e9b1791909c2ac54952bf79a798/microsoft/TypeScript/issues/25181 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/de439acaf3e51b5fe9235a260406843e55c19e9b1791909c2ac54952bf79a798/microsoft/TypeScript/issues/25181 |
| og:image:alt | TypeScript Version: 2.9.2 Code interface Spy { (...params: any[]): any; identity: string; and: Function; mostRecentCall: {args: any[];}; argsForCall: any[]; } type SpyObj |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mprobst |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width