I am trying to type a jest test.each that uses a tagged template literal
test.each`
height | text
${10} | ${undefined}
${20} | ${undefined}
${10} | ${'text'}
${20} | ${'text'}
`('$height and $text work as expected', ({ height, text }) => {
//...
});
heightis a numbertextis a string or undefined
I could, of course add my types to the tests' function parameters:
({ height, text }: { height: number, text: string? }) => {
//...
});
But this is not what I want. test.each accepts a generic type
test.each<MyType>`
height | text
// ...
`('$height and $text work as expected', ({ height, text }) => {
//...
});
and I am wondering how I can use that type to infer the types in the function parameters.