Skip to content

Commit

Permalink
Add type RequireSubType
Browse files Browse the repository at this point in the history
  • Loading branch information
pihart committed Mar 24, 2021
1 parent c121716 commit 7d3b295
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib/subtype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ import { TestedType } from "./misc";
* otherwise type `false`.
*/
export type IsSubType<A, B> = A extends B ? true : false;

/**
* Type {@typeparam A} if {@typeparam A} is a subtype of {@typeparam B};
* otherwise type `never`.
*/
export type SubType<A, B> = TestedType<A, IsSubType<A, B>>;

/**
* A stricter version of [[`IsSubType`]].
* Type `true` if {@typeparam A} is a subtype of {@typeparam B};
* compile-time error otherwise.
*/
export type RequireSubType<A extends B, B> = IsSubType<A, B>

0 comments on commit 7d3b295

Please sign in to comment.