-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to configure ToTypeScriptType to handle nullable types differently. #4
Comments
There is no global configuration for custom functions available, but in NTypewriter (contrary to Typewriter) custom functions can have parameters, thus I would just add an additional optional parameter to this method to affect its behaviour. You are welcome to prepare a pull request, just do not forget to include tests for this change. |
I would like to add a function similar to
Full example:
This would cover all cases, but requires more code in the template (not a bad thing in my opinion). What are your thoughts on this? If you agree, what should this function be named so that the distinction between |
At the current stage, breaking changes are not a problem. But in that case, I would leave the behaviour of The function that you described already exists, only needs a few tweaks: add null checking, documentation, make it public
But the name is awful and it shows that I did not have an idea how to name it. Something better is needed, that will underline distinction. And most obvious choices seem too long : ToTypeScriptTypeNotNullable ToTypeScriptTypeRaw ToTypeScriptTypeExtant and more ideas on how to replace the phrase not null :https://stackoverflow.com/questions/14273820/is-there-a-single-word-meaning-not-null |
I know you just said you want to leave the behavior of How about renaming the existing function to Or, perhaps even better, an optional boolean argument named |
I would go with the proposed |
After doing some work on this, I realized that having only an option to exclude the nullable postfix isn't going to be sufficient for my use case. Arrays and generics make things a little more complicated. The function currently produces the following:
In these cases, I'd like to be able to configure NTypewriter to use By the way, |
implement configurable nullable type, resolves #4
Currently, NTypewriter appends
" | null"
to nullable types:NTypewriter/NTypewriter.CodeModel.Functions/TypeFunctions.ToTypeScriptType.cs
Line 25 in 018ead1
I would like to be able to use any of following TypeScript notations in my templates:
I could attempt to write my own implementation of
ToTypeScriptType
, but I'd rather not copy-paste 100+ lines to change a single detail. I'd like to help out if possible, but I'm not sure where to start - I'm not sure what the best approach is here. Is there already an example of something similar to this in the code base, e.g. a configuration option that affects the behavior of a static function such asToTypeScriptType
?The text was updated successfully, but these errors were encountered: