-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected error tests involving typescript enums + zod #33
Comments
Interesting. That does indeed seem wrong but I can't see why it'd be happening. It does seem to be specific to enums. I never use enums in general in typescript because behaviour is much harder to intuit and doesn't have any real advantages over, say string literals, so there are probably some tests missing for enums. Were you able to find a way to reproduce the issue that doesn't involve as many dependencies? That'd make it easier to track down. |
Here is another example with zod. Reported with vitest but if you change the import to use |
Still can't figure out exactly what causes this, but it is likely something quite deep in TypeScript, since the default But you can easily workaround this without downgrading by using 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 now doesn't fail: ... 👇
expectTypeOf<InterfaceValidatorType>().branded.toEqualTypeOf<ExampleInterface>() I'll leave this open though because microsoft/TypeScript#55188 was closed recently, so it might be worth checking regularly to see if this is fixed by a future typescript version. |
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 withexpect-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: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 themyEnum
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:
The text was updated successfully, but these errors were encountered: