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

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.10 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.9 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.8 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts
clapton-0.0.7 lib/clapton/javascripts/node_modules/type-fest/source/is-never.d.ts