You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceSpy{(...params: any[]): any;identity: string;and: Function;mostRecentCall: {args: any[];};argsForCall: any[];}typeSpyObj<T>=T&{[kinkeyofT]: Spy;}declarefunctioncreateSpyObj<T>(name: string,names: Array<keyofT>): SpyObj<T>;/** * Creates a jasmine mock where every given method returns the spy object. */functionmock<T>(spyName: string,methodNames: Array<keyofT>): SpyObj<T>{constspyObj=createSpyObj<T>(spyName,methodNames);for(constmethodNameofmethodNames){spyObj[methodName].and.returnValue(1);// fails, Property 'and' does not exist on type 'SpyObj<T>[keyof T]'.}returnspyObj;}
Expected behavior:
In 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.
Actual behavior:
In TS 2.9, there's a type SpyObj<T>[keyof T], but apparently it does not resolve to Spy?
* unknownify accesses
* Move to simplify to break less with fewer changes
* Accept baselines for now
* Always propegate any as an index type
* Fix flow control in the presence of simplifiable types
* Add spy repro from #25181
* Retain errorType when it is used as a marker for the lack of a constraint
* Small refinement
* Add new test
* Move most potentially recursive types from isIdenticalTo into structuredTypeRelatedTo to match the non-identity relations
* Fix nits
* Doesnt need to be undefineable at all
TypeScript Version: 2.9.2
Code
Expected behavior:
In TS2.8,
spyObj[methodName]
above was any, allowingand
to be referenced on it. Ideally, this would figure out that all members ofspyObj
must at least be aSpy
.Actual behavior:
In TS 2.9, there's a type
SpyObj<T>[keyof T]
, but apparently it does not resolve toSpy
?Playground Link:
http://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
The text was updated successfully, but these errors were encountered: