Skip to main content
Module

x/scaffold/src/deps/types.ts>LiteralUnion

scaffold your next project with style and 💗
Latest
type alias LiteralUnion
import { type LiteralUnion } from "https://deno.land/x/scaffold@0.3.0/src/deps/types.ts";

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. It will be removed as soon as it's not needed anymore.

Examples

Example 1

import type {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.

Type Parameters

LiteralType
BaseType extends Primitive
definition: LiteralType | (BaseType & Record<never, never>)