Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

Exclude value from array typescript type

// Exclude Array
type Equal<T, K> = K extends T ? true : false;
type ExcludeArray<T extends any[], K, J extends any[] = []> = T extends [infer first, ...infer Rest]
	? Equal<first, K> extends false
		? ExcludeArray<Rest, K, [...J, first]>
		: ExcludeArray<Rest, K, [...J]>
	: J;
type excludeArray = ExcludeArray<['a', 'b', 'c', 'd'], 'c'>; //['a', 'b', 'd']
type excludeArray_2 = ExcludeArray<['a', 'b', 'c', 'd'], 'c'|'d'>; //['a', 'b']
 
PREVIOUS NEXT
Tagged: #Exclude #array #typescript #type
ADD COMMENT
Topic
Name
8+8 =