File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -9,13 +9,34 @@ npm install ob-scan-ts
99```
1010
1111## Usage
12+ ### Nested object to typescript types
1213``` ts
1314import { DotNestedKeys } from " ob-scan-ts" ;
1415
1516const obj = { foo: { bar: 123 , baz: 456 } };
1617type 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
You can’t perform that action at this time.
0 commit comments