Input and Output typings based on the component #478
Replies: 6 comments
-
Hi, thanks for a great typings. There is just one thing about inputs - they are not 100% correct as its based on type information only and inputs may be functions (which you excluded here). Outputs however is more accurate since it's type is distinct from everything else. I still would like to consider adding these types to the library as a helper types. But I would not want to type with them directive inputs/outputs because this may be a potential breaking changes for users. So on that note would you like to submit a PR to the lib? =) |
Beta Was this translation helpful? Give feedback.
-
Correct. It is (afaik) currently impossible to detect inputs based on the Input directive. Instead all properties must be used. It just excludes EventEmitters, since they are outputs, and functions, since it is not possible to make a distinction between a function property or a class method. I removed excluded methods, because they are more likely to be class methods than actual inputs. And in my opinion, if you're making a input property of type function, you're better off using an output instead.
Agreed. A library's api must be clear and the current types provided are fine. I just wanted something stricter to help with me and my components. Other users may have other requirements, I mostly provided the code to help with the property extraction and transformation, since that is actually the most difficult apart about the typings.
Do you reckon it is useful? The input part is rather opinionated and often 'wrong', since it also shows non- |
Beta Was this translation helpful? Give feedback.
-
I think if the type produced for inputs is more inclusive then just inputs then it's totally fine since devs still can assign inputs correctly and just have autocomplete on top - so yeas I see this as a useful thing =) Maybe we can even create 2 types for inputs:
In this way if devs will have inputs as functions they will have an option to use autocomplete with less strict type. So in total we can add 3 new type helpers:
What do you think? |
Beta Was this translation helpful? Give feedback.
-
I realize I never responded to this. Yes, I think that's a good idea. :) |
Beta Was this translation helpful? Give feedback.
-
Hey, is there still any interest in this? |
Beta Was this translation helpful? Give feedback.
-
Closing due to inactivity. |
Beta Was this translation helpful? Give feedback.
-
This is more of a post for helping other developers with their input and output typing. As we all know, Typescript's typing helps developers by preventing mistakes. I don't think the library has typings that helps the developer, so I created them myself.
Result:
These are the typings that matter.
You can use that with a config object like this:
Which you can use in your Angular template as follows:
Feel free to use. Let me know if you have improvements. Also feel free to incorporate (parts of) this in the library if you wish.
Beta Was this translation helpful? Give feedback.
All reactions