LaTeX.js icon indicating copy to clipboard operation
LaTeX.js copied to clipboard

Code-Questions for a TypeScript-Implementation

Open seuliang opened this issue 6 years ago • 8 comments

see: https://github.com/michael-brade/LaTeX.js/blob/245ca82d22c9f9d4dc34041833316667b2f17af6/src/html-generator.ls#L299

https://github.com/michael-brade/LaTeX.js/blob/245ca82d22c9f9d4dc34041833316667b2f17af6/src/html-generator.ls#L352

https://github.com/michael-brade/LaTeX.js/blob/245ca82d22c9f9d4dc34041833316667b2f17af6/src/html-generator.ls#L487

those functions adapt different arguments, how to decide arguments's type?

seuliang avatar Jul 11 '19 13:07 seuliang

  • appendChild is part of the Browser DOM API (see Node​.append​Child()).
  • appendChildren is taking Node and Array<Node>|Node
  • addAttributes: you could just read the code... the if will tell you: Element|Text|DocumentFragment or Array<Element>.
  • createDocument: takes an Array of Element to create the final DOM.

michael-brade avatar Jul 11 '19 17:07 michael-brade

You know, we could use this issue, for example, to group all your TypeScript questions. Then we don't have to use many different issues and all the information can be found on one page... I'll change the title accordingly.

michael-brade avatar Jul 11 '19 17:07 michael-brade

i agree .it's will be convenient.

i tried some types for those arguments but not appropriate for all conditions. i just want to confirm those types. i will try again. Thank you !

seuliang avatar Jul 12 '19 03:07 seuliang

https://github.com/michael-brade/LaTeX.js/blob/245ca82d22c9f9d4dc34041833316667b2f17af6/src/html-generator.ls#L299

@_dom is DocumentFragment,

https://github.com/michael-brade/LaTeX.js/blob/245ca82d22c9f9d4dc34041833316667b2f17af6/src/html-generator.ls#L497

"nodes" in "Text" and "DocumentFragment" type is not consistent to "create" argument type Element or an array of Element

seuliang avatar Jul 12 '19 09:07 seuliang

Ok, so simply change/extend the type definition for create: children type should equal the one of appendChildren or be more restrictive than it (appendChildren could even take Node or Array<Node>). However, don't confuse the type and children arguments of create.

michael-brade avatar Jul 12 '19 14:07 michael-brade

actually, I edited appendChildren in my earlier comment (https://github.com/michael-brade/LaTeX.js/issues/81#issuecomment-510588382), there is no need to be more restrictive with the types than necessary.

michael-brade avatar Jul 13 '19 09:07 michael-brade

yes. i understand. I have done some type definitions, but need more time to finish the rest and do some documentation to help me understand it.

seuliang avatar Jul 13 '19 11:07 seuliang

Hey there! I would be interested in type definitions for this package Do you have a link to a repository or gist ?

:beers: thank you!

GerkinDev avatar Nov 26 '19 19:11 GerkinDev