import { ExpectationResult } from '@vitest/expect'; expect.extend({ toBeTypeOrNull(received: any, constructor: unknown): ExpectationResult { const { isNot } = this; try { expect(received).toEqual(expect.any(constructor)); return { message: () => `Ok`, pass: true, }; } catch (error) { return received === null ? { message: () => `Ok`, pass: true, } : { message: () => `expected ${received} is${isNot ? ' not' : ''} to be ${constructor} type or null`, pass: false, }; } }, });