Sha256: b29ef0a32e75e0d2a08762d6af502c0ffcd7a83fec07ed7a153e95329b89d761

Contents?: true

Size: 1.11 KB

Versions: 65

Compression:

Stored size: 1.11 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,
	BaseType extends Primitive
> = LiteralType | (BaseType & {_?: never});

Version data entries

65 entries across 65 versions & 6 rubygems

Version Path
rapid_stack-0.2.0 templates/frontend/node_modules/type-fest/source/literal-union.d.ts
rapid_stack-0.1.1 templates/FrontEnd/node_modules/type-fest/source/literal-union.d.ts
rapid_stack-0.1.0 templates/FrontEnd/node_modules/type-fest/source/literal-union.d.ts
trusty-cms-6.3.1 node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.26 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/ansi-escapes/node_modules/type-fest/source/literal-union.d.ts