Skip to content
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

This breaks unrelated TypeScript types (extremely rare) (Zod) #31

Open
Lawlzer opened this issue Nov 22, 2022 · 1 comment
Open

This breaks unrelated TypeScript types (extremely rare) (Zod) #31

Lawlzer opened this issue Nov 22, 2022 · 1 comment

Comments

@Lawlzer
Copy link

Lawlzer commented Nov 22, 2022

Importing @colors/colors will break types (This is extremely rare --- This is the first time I have ever seen this happen)

The following code will run perfectly fine, fully type-safe. However, as soon as you import @colors/colors, it will cause an error.
Even if you import @colors/colors in a separate file (e.g inside a nested folder), it will STILL break the types!

// import colors from '@colors/colors'; // Uncommenting this line will cause the error.
// // You can also move the line to a separate file -- it will STILL cause this error.
import { z } from 'zod';

export type UnionToIntersection<U> = (U extends U ? (u: U) => 0 : never) extends (i: infer I) => 0 ? Extract<I, U> : never;
export type ArrayToIntersection<T extends readonly unknown[]> = UnionToIntersection<T[number]>;

export function arrayToIntersection<T extends readonly any[]>(arr: T): UnionToIntersection<T[number]> {
	return '' as any;
}

const tempTrash = arrayToIntersection([
	z.object({
		foo: z.object({
			one: z.string(),
		}),
	}),
	z.object({
		foo: z.object({
			two: z.string(),
		}),
	}),
]);

type TempTrash = z.infer<typeof tempTrash>;
const something: TempTrash = { foo: { one: '', two: '' } };
Lawlzer added a commit to Lawlzer/utils that referenced this issue Dec 2, 2022
This fixes an extremely rare bug (that would break a future commit): DABH/colors.js#31
@DABH
Copy link
Owner

DABH commented Jul 10, 2023

Any ideas on how to fix this? Is it only with zod?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants