Genric argument fails with "ReferenceError: t is not defined"
CristhianParra opened this issue · comments
It's possible to send the type as an argument using generics?
function genericCreateMock<T extends object>() {
return createMock<T>();
}
interface Person {
id: number;
name: string;
}
genericCreateMock<Person>() // ReferenceError: t is not defined
Hi @CristhianParra! Thanks for using ts-auto-mock!
It's not possible to achieve what you are trying to do with this library. Ts-auto-mock it's a typescript transformer that analyzes the code at compile time. Every time the library finds 'createMock' will try to create the mocks given the generic. In your case the generic is lost by the time it will try to create it. It could be that there is a way but we haven't figured that out yet.
Thanks for answering! I'm going to close the issue then
Thanks, if you want to share your code example we can try to figure out what you are trying to achieve. Why do you need a function?