Skip to content

Unexpected error tests involving typescript enums + zod #33

@electrovir

Description

@electrovir

I have not been able to narrow down what is causing this, as simple examples in a TypeScript playground do not fail. However, I'm now having issues in version 0.16.0 with .toEqualTypeOf. I have a relatively complex type builder that I'm using to extract types out of run-time values and I run type testing with expect-type to ensure the extracted types are correct.

After upgrading to version 0.16.0 of expect-type, my test now fails even though, AFAICT, the types are indeed equal:

expectTypeOf<Pick<(typeof shapeDefinition.runTimeType), 'myEnum'>>().toEqualTypeOf<{
    myEnum: TestEnum;
}>();

Here's a playground with all the needed code from my package. The failing expectType is near the bottom. Apologies for the size of the code, I narrowed it down to the myEnum property but couldn't figure out how to narrow it further.

The workaround for me for now is to revert to version 0.15.0 as it has no issues for me.


edit

Smaller, self-contained repro:

import {z} from 'zod'
import {expectTypeOf} from '../src'

// eslint-disable-next-line no-restricted-syntax
enum ExampleEnum {
  a = 0,
  b = 1,
}

interface ExampleInterface {
  prop: ExampleEnum
  prop2: string
}

const InterfaceValidator = z.object({
  prop: z.nativeEnum(ExampleEnum),
  prop2: z.string(),
})
type InterfaceValidatorType = z.infer<typeof InterfaceValidator>

// this comparison fails
expectTypeOf<InterfaceValidatorType>().toEqualTypeOf<ExampleInterface>()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions