Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

Generic typing on custom plugins not working #37

Open
zbarbuto opened this issue Jan 29, 2020 · 0 comments
Open

Generic typing on custom plugins not working #37

zbarbuto opened this issue Jan 29, 2020 · 0 comments

Comments

@zbarbuto
Copy link

zbarbuto commented Jan 29, 2020

My example use case:

export const customTest = test.register('stubApi', stubApi);

function stubService<T>(service: T, method: keyof T, ...handlers) {
  return {
    run: () => {
      test.stub((<any>service).prototype, method, ...handlers);
    }
  };
}

class MyService {
  bar() { }
}
// I would expect this to type error since 'foo' does not exist on MyService
// however it works fine
customTest.stubService(MyService, 'foo', () => 'mock foo');

I'm unsure if it's something I'm doing wrong or not but you can't even apply a typing to stubService as you get "Expected 0 type arguments". I suspect it's something to do with the way plugins are registered.

Specifically, I think here: https://github.com/oclif/fancy-test/blob/master/src/types.ts#L49 that A extends any[] is not enough to infer Parameters<typeof stubService> as it should.

@zbarbuto zbarbuto changed the title Typing on custom plugins not working Generic typing on custom plugins not working Jan 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant