I wrote my example with Dessert to make it generic. I did not find the exact solution, but found a way that will make TS tell me check my test files when some of the types are updated:
import { IsEqual } from 'type-fest'
const negativeStatusCases = ['pending', 'failed', 'cancelled', 'expired', 'in_progress'] as const
negativeStatusCases.forEach((negativeStatus) => {
describe(negativeStatus, () => {
it('shows message with variant of "warning"', async () => {
...
})
})
})
it('covers all non `succeeded` status cases', () => {
type Status = Awaited<ReturnType<typeof api.fetchPaymentStatus>>['status']
type NegativeStatus = Exclude<Status, 'succeeded'>
const allStatusCasesAreCovered: IsEqual<NegativeStatus, (typeof negativeStatusCases)[number]> = true
expect(allStatusCasesAreCovered).toBe(true)
})
hope it helps others 🙂
Desserttype from an end-point response"? TypeScript is compile-time not run-time, so I'm not sure how you could dynamically be retrieving a type from an API at run-time and have it do anything usefulmuffintoDessertthen I'll get a updated type file for this change. But I have some test that uses these types and I would then like to have TS complain that I do not testmuffinDeserttype? Also, you never did specify the array type for thearrWithAllDessertTypesvariable. Tryconst arrWithAllDessertTypes: Dessert[] = ['cake', 'chocolate', 'water']Dessert(water) AND if it is missing an dessert. It is intentional that I haven't specified the array type - this is what the question is about. How do specify a more strict type than: Dessert[]oras Dessert[]orsatisfies Dessert[]?