Skip to content

Commit 9b30b12

Browse files
Update Usage readme
1 parent 807bb62 commit 9b30b12

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,34 @@ npm install ob-scan-ts
99
```
1010

1111
## Usage
12+
### Nested object to typescript types
1213
```ts
1314
import { DotNestedKeys } from "ob-scan-ts";
1415

1516
const obj = { foo: { bar: 123, baz: 456 } };
1617
type NestedKeys = DotNestedKeys<typeof obj>; // "foo.bar" | "foo.baz"
1718
```
1819

20+
### JSON to typescript types ( i18n use case )
21+
```ts
22+
import * as en from "en.json"
23+
24+
type TranslateKey = DotNestedKeys<typeof en>
25+
26+
27+
// use TranslateKey for create a custom hook
28+
export const useAppTranslate = () => {
29+
const { t: tOrigin } = useTranslation();
30+
31+
const t = (key: TranslationKeys) => tOrigin(key);
32+
return {
33+
t,
34+
};
35+
};
36+
37+
export default i18n;
38+
```
39+
1940
## API
2041
### ```DotNestedKeys<T>```
2142

0 commit comments

Comments
 (0)