Last active
January 11, 2022 11:40
-
-
Save Tomas2D/939540879842d15087db07ffbef3f84c to your computer and use it in GitHub Desktop.
Revisions
-
Tomas2D revised this gist
Jan 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ type PathsWithStringValue<T, D extends number = 10> = [D] extends [never] : T extends string ? [] : { [K in Extract<keyof T, string>]: [K, ...PathsWithStringValue<T[K], Prev[D]>]; }[Extract<keyof T, string>]; type Join<T extends string[], D extends string> = T extends [] -
Tomas2D revised this gist
Jan 10, 2022 . 1 changed file with 17 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,15 @@ import * as error from './cs/error.json'; /* // Content of a "./cs/error.json" file { "general": { "unexpected": "Došlo k neočekávané chybě." }, "unauthorized": { "token": "Váš přístup byl zamítnut, nevalidní token." } } */ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]]; @@ -23,3 +34,9 @@ type Join<T extends string[], D extends string> = T extends [] type DottedStringPaths<T> = Join<PathsWithStringValue<T>, '.'>; export type ErrorTranslationPath = `error.${DottedStringPaths<typeof error>}`; let transErrorId: ErrorTranslationPath; transErrorId = 'error.general.unexpected' // OK transErrorId = 'error.general' // Error, `general` is not a string value transErrorId = 'error.unauthorized' // Error, `unauthorized` is not a string value transErrorId = 'error.unauthorized.token' // OK -
Tomas2D revised this gist
Jan 9, 2022 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as error from './cs/error.json'; type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]]; type PathsWithStringValue<T, D extends number = 10> = [D] extends [never] ? never : T extends string ? [] @@ -20,6 +20,6 @@ type Join<T extends string[], D extends string> = T extends [] : never : string; type DottedStringPaths<T> = Join<PathsWithStringValue<T>, '.'>; export type ErrorTranslationPath = `error.${DottedStringPaths<typeof error>}`; -
Tomas2D created this gist
Jan 9, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ import * as error from './cs/error.json'; type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...0[]]; type PathWithStringValue<T, D extends number = 10> = [D] extends [never] ? never : T extends string ? [] : { [K in Extract<keyof T, string>]: [K, ...PathWithStringValue<T[K], Prev[D]>]; }[Extract<keyof T, string>]; type Join<T extends string[], D extends string> = T extends [] ? never : T extends [infer F] ? F : T extends [infer F, ...infer R] ? F extends string ? `${F}${D}${Join<Extract<R, string[]>, D>}` : never : string; type DottedLanguageObjectStringPaths<T> = Join<PathWithStringValue<T>, '.'>; export type ErrorTranslationPath = `error.${DottedLanguageObjectStringPaths<typeof error>}`;