Skip to content
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

Feature request: Improvement in regards to TS support #423

Open
mateusz-matyjaszczyk opened this issue Sep 24, 2024 · 3 comments
Open

Feature request: Improvement in regards to TS support #423

mateusz-matyjaszczyk opened this issue Sep 24, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@mateusz-matyjaszczyk
Copy link

Describe the feature
Currently when you select "(TS) Generate interfaces for XML files (id to class mapping)" you get something like this:
CleanShot 2024-09-25 at 03 41 33@2x

which is fine but at the end you still have to use id as string when you want to get the reference to that control via this.byId('id').
What I would like to see is something like this:
CleanShot 2024-09-25 at 03 39 30@2x

Where you get the Ids and types so you can reference to that Id using defined object which improves code quality and limits possibility of typos etc + if you ever change that Id it is very easy to check all the references to it.

@iljapostnovs
Copy link
Owner

iljapostnovs commented Sep 24, 2024

Hi,

This approach has a lot of disadvantages, so instead of talking about it, I will recommend to check out the blog -> Control type casting section. Try to implement it, it covers your needs and additionally removes the necessity of type casting.

@mateusz-matyjaszczyk
Copy link
Author

Got it and thank you!
Is it possible that you could explain those disadvantages? I am new to TS and if there is anything to learn i am willing to dig :).

@iljapostnovs
Copy link
Owner

Sure.
The main disadvantage of your approach is that it requires real code to be generated from typescript to javascript.
Types are disappearing in compilation phase, meaning that all the interfaces which my extension is generating will not be there in javascript.

With your approach it is unclear how and where to generate the IDs. In your example ids are generating right above the class itself, which is kind of tricky for extension to generate and it is not error prone for e.g. dynamic fragment loading, when it is impossible to tell from code perspective which fragments are connected to the class where ids are generated. So maybe the best way there could be to generate a separate enumeration file and use it everywhere. However, again, it will be a real boilerplate code which will be compiled to javascript, without real necessity in it.

With my proposal only types are generated, which are not compiled to javascript, and the usage of ids is not changing (it doesn't require any enumerations), so it is more intuitive to use, and, additionally, return type is determined automatically which helps to avoid manual casting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants