As before, generalities don't really help but specific instances will.
1. As the docs say, Object means a plain JavaScript Object. As with JavaScript in general, an Object can have methods added it to it as properties. What specific API(s) are you looking at where it's unclear what to generate for TypeScript?
2. methods can't have IRWA flags at all (there is not even a way to declare such a thing in our JS doc format), so what specific methods do you think have an "I" flag? Yes, method overrides and custom methods can be passed to create(), there is no need for a special flag to allow this
Announcement
Collapse
No announcement yet.
X
-
I'm making good progress. I am almost to the point where everything works for my project (subset of classes/objects and subset of methods). There are, of course, lots of issues with the referenceDocs.xml file, too many to list in the forum here so part of my program will now try to identify the issues and generate a report so that we may easily keep track of them. I have a few fundamental questions though:
1. How is an object (called plain old javascript object in the docs) different than a class? At first I thought it might be that an object doesn't inherit from anything or have methods but I've found examples that violate those rules. So what is the rule that makes an object an object vs. a class? If I know the rule, then I can easily validate the file. It doesn't really matter to the TypeScript definition library, everything is an interface anyway, but I'm curious and if you've decided to call them different things, then there must be a reason.
2. I'm using the I flag to create 'Properties' interfaces. These represent classes (or objects?) that can be created and type-checked inside a call to .create(). For example, if you typeCode:isc.TabSet.create({
Leave a comment:
-
Right, it's common in OOP systems to re-doc a property on a subclass to explain different behavior, different default value, etc.
All of the types declared for SCImgDir are just strings, but we'll clean this up so they all say SCImgURL.
Similarly, the valuesManager property does allow either a ValuesManager or (String) ID of a valuesManager, we'll make that consistent as well.
BaseWidget was recently introduced to explain some drag-and-drop properties that are in common between Canvas and DrawItem, and so missed out on the @inheritsFrom docs we added everywhere - we'll get that one corrected too.
Leave a comment:
-
More weirdness: Some classes which inherit from other clasess implement the (seemingly) same property but with a different type. For example: TabSet has a skinImgDir property of type string but it inherits from Canvas which has a skinImgDir property of type URL. Of course they're both really strings by why would a sublass redefine a property? I see that the TabSet version has a default value. Is that why?
Similarly, DynamicForm redefines valuesManager (as ValuesManger | global id) from Canvas (which is just ValuesManager) but neither has a default value. Are these on purpose?
Leave a comment:
-
We haven't proposed keeping anything in your script that would need to be revisited when new versions of SmartClient are released.
Adding version information to referenceDocs.xml makes sense, we'll try to get that done soon. For now, you could pull this information from either the .zip download filename or from docs/readme.html.
Leave a comment:
-
Yes, I am already working around the inconsistencies and that will work for now. If, however, we want to maintain an up-to-date typedef file(s) as new versions are released, then we'd want that to be auto-generated and not have to implement new workarounds. Which brings up another idea. Can we get some kind of version number in the referenceDocs file? Maybe in a top-level root tag or something. Currently I am modifying the file to add a root tag anyway (because the .NET parser wants one) but it would be nice to have some global info like the version number, build date etc which would then end up in the typedef files as well.
Leave a comment:
-
Look like you've hit a few of the instances where the SmartGWT Java API is hand-coded rather than generated, so the reference docs for those properties weren't corrected to be a machine-readable description of the type (that explains ListGridField.includeInRecordSummaryFields, DataSourceField.filterEditorType, and LayoutProperties.placeHolderProperties). We'll get these three fixed - please keep letting us know about any of these as they can be quickly fixed.
As far as "or" vs "|", and the 3 array notations - yes, our own tools are tolerant of these minor variations. We'll get this cleaned up, standardizing on "|" and the "Array of " wording, but to be able to proceed we'd recommend just having your script deal with these variations (which should be easy).
Note we won't be going with your suggestion of separate valueType tags as that becomes quite verbose for things like parameters, and it usually doesn't make sense to have completely different descriptions for each possible argument type.
Leave a comment:
-
It's general inconsistencies in the way that properties are defined that makes it tough. Here are some Examples:
ListGridField.includeInRecordSummaryFields: array of fieldNames <-- fieldNames is pluralized. Also the way of specifying arrays is inconsistent. Would prefer just FieldName[] or string[].
DataSourceField.filterEditorType: FormItem className <-- Again, this is really a string, Hopefully the baseType will fix that.
Menu.data: Array of MenuItem | Array[] of Record | Tree | RecordList <-- Array is specified in two different ways for the same property. Or is specified with |
Validator.dependentFields: String[]<-- Another way an array is specified
UserTask.targetVM: ValuesManager or String <-- Or is specified with or.
LayoutProperties.placeHolderProperties: canvas properties <-- Canvas is not capitalized
If I had my way, all arrays would be specified as T[] or Array<T> if it really uses an Array object and Or would always be specified with a pipe |. This maps nicely to (future)JavaScript and TypeScript without any transformation. Also, it would be nice if things were all Capitalized correctly and not pluralized. These things, of course, are all nit-picky details for a human to figure out but require extra rules when read by a program.
If you're considering modifying the schema, one change that might make it easier for all kinds of code/document generation is converting the type attribute to a tag and allow multiple type tags per property. This would allow any code-generator to easily parse union types and format them in the appropriate (using |, or OR or a comma-seperated list like This,That, or TheOther) way either for documentation or for code. For example
Code:<docItem defaultValue="null" type="attr" definingClass="class:Menu" ref="attr:Menu.data" valueType="Array of MenuItem | Array[] of Record | Tree | RecordList" description="An array of menuItem objects, specifying the menu items this menu should show.&#010&#010 Data may also be set to a ${isc.DocUtils.linkForRef('class:Tree')} in which case a hierarchy of menus and&#010 submenus will automatically be generated to match the tree structure. See also&#010 ${isc.DocUtils.linkForRef('attr:Menu.dataSource')} for dynamically fetching menuItems and submenus from a&#010 hierarchical DataSource." flags="IRW" name="data"> <groups>data</groups> <setter>setData</setter> <examples>${isc.DocUtils.linkForExampleId('fullMenu')}</examples> </docItem>
Code:<docItem defaultValue="null" type="attr" definingClass="class:Menu" ref="attr:Menu.data" flags="IRW" name="data"> <valueType type="MenuItem[]" description="An array of MenuItem objects, specifying the menu items this menu should show"> <valueType type="Record[]" description="An array of Records, specifying the menu items this menu should show"> <valueType type="Tree" description="a Tree in which case a hierarchy of menus and submenus will automatically be generated to match the tree structure"> <valueType type="RecordList" description="A RecordList object because..."> <valueType type="Record[]" description="An array of Records, specifying the menu items this menu should show"> <groups>data</groups> <setter>setData</setter> <examples>${isc.DocUtils.linkForExampleId('fullMenu')}</examples> </docItem>
Leave a comment:
-
We don't plan to add "baseType" declarations for int, float, etc as that's a small, static, self-explanatory list. However it would be great to hear about any further issues you discover that make it difficult to translate to a TypeScript API definition (or, like the string-based types, require information to be maintained inside the translation script).
Leave a comment:
-
recall, we actually generate full Java interfaces from this information
Currently, for the handful of types like CSSStyleName which are basically strings, for translation to Java APIs we just have a list of them in the translation tool, and the list is:
We'll look at adding something like adding a ' baseType:"String" ' property to referenceDocs.xml
We can fix this one, let us know if you find others.
I made a lot of progress today but nothing to upload yet.
Leave a comment:
-
No language can enforce (at compile time) every constraint that a programmer might wish for.
Not to mention that, of course, systems like XML Schema allow such constraints for data values, and in many ways, the distinction between data values and parameter values is blurring (isn't an XML element passed to a WSDL web service basically a method parameter?). In fact, SC's type system allows you to attach not just constraints but also behaviors to atomic types - SimpleTypes in SmartClient can extend each other, and add value constraints, parsing and formatting rules, default editors to use, etc.
So, we definitely will not be changing our reference to show just Number where we currently show int, float, etc as it clearly provides useful information in a compact, easily understood format. Similarly for things like CSSStyleName - we find this a lot better than having docs throughout the system link to an explanation of what to pass, and the fact that the information is structurally part of the doc makes it much easier to build tools for editing component properties.
However we would like to make referenceDocs.xml, or a derivative format, easier to process for TypeScript *and other possible targets* (recall, we actually generate full Java interfaces from this information).
Currently, for the handful of types like CSSStyleName which are basically strings, for translation to Java APIs we just have a list of them in the translation tool, and the list is:
<class name="Callback"/>
<class name="ListGridGroupState"/>
<class name="RelativeDateString"/>
<class name="CSSClass" />
<class name="CSSText" />
<class name="CSSColor" />
<class name="CSSClassName" />
<class name="CSSStyleName" />
<class name="Color" />
<class name="SCClassName" />
<class name="SCImgURL" />
<class name="DataPath" />
<class name="DateInputFormat" />
<class name="ListGridFieldState" />
<class name="ListGridSelectionState" />
<class name="ListGridSelectedState" />
<class name="ListGridSortState" />
<class name="ListGridViewState" />
<class name="TreeGridOpenState" />
<class name="TreeGridViewState" />
<class name="FormItemBaseStyle" />
<class name="VelocityExpression" />
<class name="XPathExpression" />
<class name="HTMLString" />
<class name="DetailViewerViewState" />
<class name="FormatString" />
For now, we'd suggest just using this same list in the TypeScript translation script. We'll look at adding something like adding a ' baseType:"String" ' property to referenceDocs.xml so this list doesn't need to be hardcoded into the translation script, but we're very focused on the 11.1 / 6.1 release right now, so there will be some delay.
For the NavigationMode enum, those values are the names of constants, so you can actually evaluate "TableView.NAVICON_ONLY" to get the string "naviconOnly". However, we went through and eliminated these as part of making our docs more easily translate to Java. We can fix this one, let us know if you find others.
Leave a comment:
-
It's true that TypeScript / JavaScript lacks the richness of SC's type system
but this is definitely not a reason to dumb down our own reference documentation, as that just removes extremely valuable information that developers need
This issue has actually bugged me in the docs even before I started using TypeScript. Many times I would encounter something like CSSStyleName and wonder what that is, then looking further at the docs I see that it is really just a 'string' and since in JS, there is no type enforcement, it's not like I could create a new CSSStyleName object and pass it in. It's just a string that should, hopefully, match up to a style name in a CSS file. I wished it would have just said the type is 'string' and the description would explain what the string represents. Of course I come from an OOP background, not JavaScipt so that may affect my thinking.
Now, however, with TypeScript, we can actually define a type called CSSStyleName (which is really still just a string, after I fix it) but the intellisense will have documentation explaining what kind of string it is so the developer will get that information immediately without having to look it up in the docs.
Intellisense in Visual Studio (yes, I know I still need to remove the encoding in the description)
Those are my opinions, take 'em or leave 'em. As for fundamental types, yes it is very easy to map Integer, int, float, Float, positiveInteger (and whatever else I find) to number. I am already putting the original type field in the comments (see the isc.classes.d.ts file in the repository) and could also include them in the JSdoc field (although it might appear to be redundant in some cases if that information is already in the description field).
for example, no way to subclass or constrain the expected values of Strings
The Bad news: Many of these string 'enums' do not contain the actual strings in the <values> tag. They appear to contain a reference to a constant or something although in most cases, I cannot find the definition of the constant. For example NavigationMode has the values TableView.WHOLE_RECORD and TableView.NAVICON_ONLY which really become "wholeRecord" and "naviconOnly" (according to the Docs but I don't know how it figured that out). I don't know how to get the real values from the values in the <values> tag. If they all follow the same pattern like, "remove the period and everything before it, strip the underscore and convert to camelCase", then I can write a transform function to do that. Or maybe the docs could be modified to just contain the actual values? Please advise.
That's it for now. Please have a look at the git repository as I think it will make some of the issues clearer, especially if viewed by someone familiar with TypeScript.
Leave a comment:
-
[quote]For example integer, Integer, int, float, and Float are all things that we understand ... [/url]
It's true that TypeScript / JavaScript lacks the richness of SC's type system, but this is definitely not a reason to dumb down our own reference documentation, as that just removes extremely valuable information that developers need. The right place to "dumb down" the types is in the script that translates from SC's type information to TypeScript's less rich type system. This also allows improvements to be made as TypeScript gets richer.
That script should, for example, translate "float" to the JavaScript Number type, but also add a note to the docs for the target attribute or method parameter saying that floating point numbers are expected or allowed. We take this same kind of approach when generating SmartGWT's Java API from SC's reference for cases where Java's type system is also too weak (for example, no way to subclass or constrain the expected values of Strings).
Given this, is there anything you see that needs fixing in the referenceDocs.xml file?
Note: we're not reproducing an issue with the SmartClient Reference with the latest available 11.1 build (4-18-2017). You may need to clear cache.
Leave a comment:
-
Ok, I've got a github repository going and I've uploaded two files: isc.types.d.ts and isc.classes.d.ts. These are both 100% code-generated from the referenceDocs.xml file (with a bunch of rules to fix the previously mentioned type issues). The types file compiles but the classes file does not. So far, I'm generating only a small subset of classes including Class, BaseWidget, Canvas, Layout, VLayout, ListGrid, Tabset and Tab. I'm only doing the properties, no methods yet and only on the instance (not the static class). If I tried to include everything, the files will be huge so I'll need to figure out how to break them up. I'm NOT a TypeScript expert. This effort is to help me with my first TypeScript project which is also a SmartClient project. If there are TypeScript gurus out there that would like to advise on file structure etc. please let me know.
By looking at the generated code, it becomes obvious (to me anyway) the issues faced with the referenceDocs data. I'm sure we can get it cleaned up but it will take a few iterations. In many cases, I bailed and just used any. This is a good way to get it going but eventually I'd like to get everything properly typed.
https://github.com/kylemwhite/isc
Leave a comment:
Leave a comment: