Skip to content

Commit e12c868

Browse files
author
Gijs Nieuwenhuis
committed
Rename d.ts. to .ts to be able to be able to use Serializable type in other projects also + add documentation
1 parent e24ee91 commit e12c868

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ A library containing javascript utilities that we until now often copy between p
3636
- [`cookieStorage`](#cookiestorage)
3737
- [Cache](#cache)
3838
- [`createInMemoryCache`](#createinmemorycache)
39+
- [Types](#types)
40+
- [`Serializable`](#serializable)
3941

4042
## Utilities
4143

@@ -528,6 +530,24 @@ cache.clear();
528530
cache.count();
529531
```
530532
533+
## Types
534+
535+
### `Serializable`
536+
537+
An interface that can be used to only allow properties that are serializable. Usable for JSON serialization or as a validation for Redux global state data.
538+
539+
Usage:
540+
541+
```typescript
542+
import { Serializable } from '@freshheads/javascript-essentials/build/types/utility';
543+
544+
const toJson = (values: Serializable): string => JSON.stringify(values);
545+
546+
class SomeClass {}
547+
548+
toJson({ value: new SomeClass() }); // = typescript error
549+
```
550+
531551
# Todo
532552
533553
- [Money formatting](https://github.com/freshheads/013/blob/develop/assets/frontend/src/js/utility/numberUtilities.ts)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Not named as utility.d.ts because it will then not be outputted into the build dir
2+
13
export type Serializable =
24
| null
35
| boolean

0 commit comments

Comments
 (0)