Friday, December 7, 2018

killer keyof IntelliSense at TypeScript in Visual Studio Code

In Visual Studio Code I see a red squiggly line underneath doSomething here:

spyOn({}, 'doSomething');

 
 

This is because {} does not have a doSomething method, but how can the IntelliSense pick that up? Well, If I put my cursor on spyOn and press F12 to drill into it. I see this at \node_modules\@types\jasmine\index.d.ts:

declare function spyOn<T>(object: T, method: keyof T): jasmine.Spy;

 
 

The keyof is empowering this magic.

No comments:

Post a Comment