Skip to content

Instantly share code, notes, and snippets.

@erassynathingo
Last active July 31, 2023 21:58
Show Gist options
  • Save erassynathingo/6bce4e97ded5a1704798e2dd505d897b to your computer and use it in GitHub Desktop.
Save erassynathingo/6bce4e97ded5a1704798e2dd505d897b to your computer and use it in GitHub Desktop.
export type Letters = 'a' | 'b' | 'c';
type RemoveC<TType> = TType extends 'c' ? never : TType;
type WithoutC = RemoveC<Letters>;
// Without C is not of type 'a' | 'b'
// We can return different mebers of the type or manipulate them. Returning never removes the element
// You can replace never with anything e.g. 'd' which means typeWithoutC will now be equal to 'a' | 'b' | 'd'
// This can be applied to enums too
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment