DABH/colors.js

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

Lawlzer opened this issue · 1 comments

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: '' } };
DABH commented

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