Skip to content

Instantly share code, notes, and snippets.

@tvler
Created June 9, 2021 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvler/e1f3cd188dc1b8f680b496fbae4d74ce to your computer and use it in GitHub Desktop.
Save tvler/e1f3cd188dc1b8f680b496fbae4d74ce to your computer and use it in GitHub Desktop.
A way to test if a Type adheres to a wider Supertype, without widening the initial Type
type Guard<Type extends SuperType, SuperType> = Type;
const tuple = [1, 2, 3] as const;
type Test = Guard<typeof tuple, ReadonlyArray<number>>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment