I'm creating a helper method to generate data for our tests. All I want is to be able to get the keys and types of the values of T so I can use it to create mocked values.
export class GenericMockFactory<T extends { id: number }>> {
makeMockModel(): T {
return {
//Mocked Data Here
}
}
}
So let's say T is
Model {
id: number
name: string
country: string
}
And I have the mockFactory as
const mockFactory = GenericMockFactory<Model>
I'd like the return of mockFactory.makeMockModel()
to be the Model
object with values set as `any_${key}`
if the type of the property is string and 1
if it's a number. For the example above:
{
id: 1
name: 'any_name'
country: 'any_country'
}
What I've tried:
Object.entries(T).forEach()
, which would be my go to if I had the object instantiated, I can't pass in a type, it seems.