Skip to main content
Module

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

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

Create a union of the given object's values, and optionally specify which keys to get the values from.

Please upvote this issue if you want to have this type as a built-in in TypeScript.

Examples

Example 1

// data.json
{
	'foo': 1,
	'bar': 2,
	'biz': 3
}

// main.ts
import type {ValueOf} from 'type-fest';
import data = require('./data.json.d.ts');

export function getData(name: string): ValueOf<typeof data> {
	return data[name];
}

export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
	return data[name];
}

// file.ts
import {getData, onlyBar} from './main';

getData('foo');
//=> 1

onlyBar('foo');
//=> TypeError ...

onlyBar('bar');
//=> 2

Type Parameters

ObjectType
optional
ValueType extends keyof ObjectType = keyof ObjectType
definition: ObjectType[ValueType]