-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.d.ts
31 lines (26 loc) · 806 Bytes
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
Define a [lazily evaluated](https://en.wikipedia.org/wiki/Lazy_evaluation) property on an object.
@param object - Object to add the property to.
@param propertyName - Name of the property to add.
@param valueGetter - Called the first time `propertyName` is accessed.
@example
```
import defineLazyProperty from 'define-lazy-prop';
const unicorn = {
// …
};
defineLazyProperty(unicorn, 'rainbow', () => expensiveComputation());
app.on('user-action', () => {
doSomething(unicorn.rainbow);
});
```
*/
export default function defineLazyProperty<
ObjectType extends Record<string, any>,
PropertyNameType extends string,
PropertyValueType
>(
object: ObjectType,
propertyName: PropertyNameType,
valueGetter: () => PropertyValueType
): ObjectType & {[K in PropertyNameType]: PropertyValueType};