Sha256: 091af8276fbc70609a00e296840bd284a2fe29df282f0e8dae2de9f0a706685f

Contents?: true

Size: 1.13 KB

Versions: 48

Compression:

Stored size: 1.13 KB

Contents

import {Primitive} from './basic';

/**
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.

Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.

This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.

@example
```
import {LiteralUnion} from 'type-fest';

// Before

type Pet = 'dog' | 'cat' | string;

const pet: Pet = '';
// Start typing in your TypeScript-enabled IDE.
// You **will not** get auto-completion for `dog` and `cat` literals.

// After

type Pet2 = LiteralUnion<'dog' | 'cat', string>;

const pet: Pet2 = '';
// You **will** get auto-completion for `dog` and `cat` literals.
```
 */
export type LiteralUnion<
	LiteralType extends BaseType,
	BaseType extends Primitive
> = LiteralType | (BaseType & {_?: never});

Version data entries

48 entries across 24 versions & 1 rubygems

Version Path
trusty-cms-6.3.1 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-6.3.1 node_modules/read-pkg-up/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.7 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.7 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.6 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.6 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.5 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.5 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.4 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.4 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.3 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.3 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.2 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.2 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.1 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.1 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-4.3.5 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-4.3.5 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.0 node_modules/type-fest/source/literal-union.d.ts
trusty-cms-5.0.0 node_modules/read-pkg/node_modules/type-fest/source/literal-union.d.ts