-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat(docgen): improve typescript generator #25
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
Conversation
- generate Global properties - generate namespace and interface for modules
Here is the result for this + #24 + tidev/titanium-sdk/pull/11348 |
Tested file from the comment above with DefinitelyTyped linter. Work fine. Even found an error in the tests. |
- remove trailing spaces from jsdoc - use "any[]" as parameter for Ti.Database.DB.execute - use "Array<Dictionany<T>>" type instead of "Dictionary<T>[]" - add "tslint:disable-next-line:ban-types" for "Function" type - update TypeScript Version to 3.0: "excluded" methods are typed as properties with "methodName: never", this is not allowed before 3.0
generated class for Titanium will have only static members
It is valid to pass a function (e.g. "onload") to Ti.Network.createHTTPClient() in Dictionary<Ti.Network.HTTPClient>. So now we exclude from T only Functions that came from Ti.Proxy Since SDK 9.0 accessors will be removed, so they will not bother us here.
5e555c5
to
c9571cc
Compare
8fc4b97
to
8443b56
Compare
Last changes:
Now (after tidev/titanium-sdk#11348 is merged) it is possible to generate valid definitions with this generator. I think, I'm finally done here. @janvennemann please review. |
3d6efa8
to
ae6483d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drauggres First of all, a big thank you for porting this to the existing typescript generator. The typed create functions and events are super awesome!
I did a first pass through this and added a couple of notes. I also have a question about one of the things you removed:
removed canExtend + removeMembers: were not really useful, only could decrease size of the output, but removeMembers did not take in accout excludes, so result was incorrect.
Instead of just ripping it out completely, why not improve it to respect excludes
? Your generated output is twice the size of how it was before. Did you test it with excludes
to see if it's worth it?
We don't need |
886557a
to
4ad7a41
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drauggres Awesome, the size looks much better now.
I copied the generated types with this PR over to the types in DefinitelyTyped and tried to run npm run lint titanium
to see if it validates. It's spitting out errors about duplicate identifiers console
and JSON
. Can you check that? Removing dom
gets rid of the console
error. But JSON
seems to be always included, even with es5
only. Do we need to exclude that in our typings?
The only remaining thing i'd really like to change are the event names to have a consistent camel-cased naming scheme, but since that is not possible due to technical limitations i guess we have to go with the underscored names.
I didn't try to run the linter after this comment (only compiled my projects with new definitions).
Work fine for me even with
It looks like we can't (and probably shouldn't) declare
Also, because I added
|
I see the following error when including
So we can't use both together or it will blow up. But we also can't exclude our global This is kind of a mess, especially when using TypeScript in Alloy (as it uses
Agreed, we should remove
Ok, that's odd. I don't see those linting issues. These are the only linting issues is see once i resolve the above issues (removed
|
There is no
For some reason they don't come up when I run linting in
Line 1152 is
That is a valid error: |
Sry, my bad, it seems like i was running an outdated version of your branch. Regenerated it and now the error is gone.
Duh, of course! About time to update our tests inside DefinitelyTyped, which is where i got that from. Everything seem to be sorted out now, approved! Awesome work man! |
this
inaddEventListner
,removeEventListener
:namespace
andclass
(with static methods). This allows to define types for specific events for Modules likeTi.Geolocation
,Ti.Media
,Ti.Network
etc.:Additonal changes:
id?: string|number
inTi.Proxy
Titanium.Database.DB.execute
Explanations:
${ClassName}BaseEvent
(e.g.ButtonBaseEvent
)${ClassName}_${EventName}_Event
(e.g.Button_click_Event
) and extended from the base eventButtonEventMap
):
in the name of a event is replaced with_
for generated interfaces (event name itself is not changed)IMPORTANT: event interface name is not documented and is generated as shown above. Since they will be in users code (if they decide to write in TypeScript), they could not be changed at any time. These names will be part of the API and must remain stable.
canExtend
+removeMembers
: were not really useful, only could decrease size of the output, butremoveMembers
did not take in accoutexcludes
, so result was incorrect.generateMethodOverloadsIfRequired
: as was mentioned in the function description:TypeScript can handle this case e.g.
add(view: Titanium.UI.View | Titanium.UI.View[]): void;
init
method: since for one module could be generated two nodes (interface and namespace) in order to decrease output size I'm skipping namespace node without any internal interfaces and namespaces. To do this I need at first to build "the tree" and then deside where I want to keep properties and methods/functions.Only thing that makes impossible to use generated file to write in TypeScript is the problem with PickerColumnUPD: APIs from files under
apidoc/Modules
are removed from output. It is incorrect to put them inside oftitanium/index.d.ts
(ideally they should be placed in separate filesti.cloud/index.d.ts
andti.cloudpush/index.d.ts
).More things came up:
global.console
andglobal.JSON
variables (currently they are interfaces) (docs: fix global methods and properties titanium-sdk#11464)global.console
(log
/err
/warn
/info
/debug
accepts "vararg") (docs: add "repeatable" property on methods parameters titanium-sdk#11468)