-
Notifications
You must be signed in to change notification settings - Fork 0
Templates
Anton edited this page Aug 10, 2019
·
1 revision
After Closure compilation, the source code will loose all annotated types.
To enable types again for developer experience of those who will use the package, the types need to be overridden. This can be achieved with the template feature of Typal. The process is the following:
- Create the
src/depack.jsfile that imports APIs from the source, and assigns them tomodule.exportsobject using quoted props notation, so that the properties don't get renamed, for example:import '../types/externs' import { Type, Property, Method, getNameWithDefault, parseFile, getLinks } from './' module.exports = { '_Type': Type, '_Property': Property, '_Method': Method, '_parseFile': parseFile, '_getLinks': getLinks, }
- Compile the source code into
compile/package-name.jsfile using thedepackcommand:{ "compile": "depack src/depack -c -o compile/package-name.js -a -p -s -O 2018 --source_map_include_content" }
- Create a template file
compile/template.js, that requires the compiled file: %EXAMPLE: src/template.js% - Run Typal to include the correct annotations, with
-targument pointing to the folder with all types (each XML file will be read recursively):typal compile/template.js -T compile/index.js -t types
The tags supported by the template are @methodType and @fnType, where the method type is used to enrich methods with JSDoc, and the function type is used to place JSDoc above methods of a class.