Sha256: 18b86125c67d99150f54225df07349ddd07acde086b55f3eeac1c34c81e424d8

Contents?: true

Size: 852 Bytes

Versions: 52

Compression:

Stored size: 852 Bytes

Contents

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

Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.

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

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

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
```

@category Object
*/
export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];

Version data entries

52 entries across 52 versions & 3 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/type-fest/source/value-of.d.ts
clapton-0.0.26 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.25 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
immosquare-cleaner-0.1.50 node_modules/type-fest/source/value-of.d.ts
clapton-0.0.24 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.23 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.22 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.21 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.20 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.19 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.18 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.17 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.16 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.15 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
immosquare-cleaner-0.1.49 node_modules/type-fest/source/value-of.d.ts
clapton-0.0.14 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
immosquare-cleaner-0.1.48 node_modules/type-fest/source/value-of.d.ts
clapton-0.0.13 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.12 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts
clapton-0.0.11 lib/clapton/javascripts/node_modules/type-fest/source/value-of.d.ts