type alias types.AllowInputKeyIfInputCanExtendOutput

Given some object TInput, and some value TOutputValue, allows any key of TInput that can be assigned to TOutputValue.

Examples

Example 1

import { AllowInputKeyIfInputCanExtendOutput } from "./types.ts";

interface SomeInput {
  inString: string;
  inStringOrUndefined: string | undefined;
  inNumber: number;
}

type SomeOutput = string | undefined;

type AllowedKey = AllowInputKeyIfInputCanExtendOutput<SomeInput, SomeOutput>;

let key: AllowedKey = "inString";
key = "inStringOrUndefined";
// key = "inNumber"; // type error

Type Parameters

TInput
TOutputValue

Definition

[TInputKey in keyof TInput]: TInput[TInputKey] extends TOutputValue ? TInputKey : never[keyof TInput]

Usage

import { types } from ".";