source: trip-planner-front/node_modules/type-fest/source/value-of.d.ts@ 84d0fbb

Last change on this file since 84d0fbb was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 829 bytes
Line 
1/**
2Create a union of the given object's values, and optionally specify which keys to get the values from.
3
4Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438) if you want to have this type as a built-in in TypeScript.
5
6@example
7```
8// data.json
9{
10 'foo': 1,
11 'bar': 2,
12 'biz': 3
13}
14
15// main.ts
16import {ValueOf} from 'type-fest';
17import data = require('./data.json');
18
19export function getData(name: string): ValueOf<typeof data> {
20 return data[name];
21}
22
23export function onlyBar(name: string): ValueOf<typeof data, 'bar'> {
24 return data[name];
25}
26
27// file.ts
28import {getData, onlyBar} from './main';
29
30getData('foo');
31//=> 1
32
33onlyBar('foo');
34//=> TypeError ...
35
36onlyBar('bar');
37//=> 2
38```
39*/
40export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];
Note: See TracBrowser for help on using the repository browser.