Skip to content

Instantly share code, notes, and snippets.

View Emiltayeb's full-sized avatar

Emil Tayeb Emiltayeb

View GitHub Profile
@Emiltayeb
Emiltayeb / gist:93257e468ae875b9636f96f992fea5d4
Last active March 20, 2023 11:21
Type Advance types - array intersection
// Construct a type that checks if 2 array are interscting
type ToUnion<T extends unknown[]> = T[number];
type IntersectionArrays<T extends any[], U extends any[]> = T["length"] extends 0 ? true :
{ [K in ToUnion<T>]: K extends ToUnion<U> ? false : true }[ToUnion<T>] extends true ? true : never
// Will resolve true since no intersection found
type A = IntersectionArrays<[1], [2]>