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
Uh oh!
There was an error while loading. Please reload this page.
-
I think recently added
isLocaleandisNamespacefunctions 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 Localesandnamespace is Namespacesas a return type ofisLocaleandisNamespacefunctions is all that's needed. Note that it should also work with JSDoc@returnsannotation (@returns {locale is Locale}).I tried implementing this feature myself by following the
CONTRIBUTING.mdfile but I couldn't figure out the testing part of generator files (regardless of multiplepnpm testandpnpm test:update-generated-filescalls, 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.mtspackages/generator/src/output-handler.mtsBeta Was this translation helpful? Give feedback.
All reactions