Use type predicates for isLocale
and isNamespace
functions
#475
mateuszaliyev
started this conversation in
DX improvements
Replies: 2 comments 4 replies
-
Thanks @mateuszaliyev! Indeed this would be a great feature, I didn't think of when I have implemented the function. Can you please share what didn't work for you? And thanks for your detailed examples! |
Beta Was this translation helpful? Give feedback.
4 replies
-
I have made the changes and released version |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think recently added
isLocale
andisNamespace
functions would be perfect use cases for type predicates. Thanks to this feature TypeScript would be able to narrow down the type of passed locale/namespace parameters.Current implementation:
With type predicates:
Adding
locale is Locales
andnamespace is Namespaces
as a return type ofisLocale
andisNamespace
functions is all that's needed. Note that it should also work with JSDoc@returns
annotation (@returns {locale is Locale}
).I tried implementing this feature myself by following the
CONTRIBUTING.md
file but I couldn't figure out the testing part of generator files (regardless of multiplepnpm test
andpnpm test:update-generated-files
calls, it would not generate any files) so I'm creating a discussion instead. Just in case it happens to be useful, those are the changes I made:packages/generator/src/files/generate-util.mts
packages/generator/src/output-handler.mts
Beta Was this translation helpful? Give feedback.
All reactions