Sha256: 4e251317bb109337e4918e5d7bcda7ef2d88f106cac531dcea03f7eee1dd2240
Contents?: true
Size: 1.04 KB
Versions: 28
Compression:
Stored size: 1.04 KB
Contents
/** Returns a boolean for whether the given type is `never`. @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919 @link https://stackoverflow.com/a/53984913/10292952 @link https://www.zhenghao.io/posts/ts-never Useful in type utilities, such as checking if something does not occur. @example ``` import type {IsNever, And} from 'type-fest'; // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts type AreStringsEqual<A extends string, B extends string> = And< IsNever<Exclude<A, B>> extends true ? true : false, IsNever<Exclude<B, A>> extends true ? true : false >; type EndIfEqual<I extends string, O extends string> = AreStringsEqual<I, O> extends true ? never : void; function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> { if (input === output) { process.exit(0); } } endIfEqual('abc', 'abc'); //=> never endIfEqual('abc', '123'); //=> void ``` @category Type Guard @category Utilities */ export type IsNever<T> = [T] extends [never] ? true : false;
Version data entries
28 entries across 28 versions & 2 rubygems