Skip to content

Commit

Permalink
Merge pull request #30 from pihart/require-subtype
Browse files Browse the repository at this point in the history
Add type RequireSubType
  • Loading branch information
pihart authored Mar 24, 2021
2 parents 9419a4e + 7d3b295 commit e9204af
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 e9204af

Please sign in to comment.