use svelte compiler to generate TypeScript definitions, documentation #228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a build step that uses Rollup and the Svelte compiler to generate TypeScript definitions. The exported modules from the entry file are used to document the public API. Additional, human-readable documentation can be generated as well.
Approach
The Svelte compiler is used to extract component metadata, including exported props, slots (default and named) and events (forwarded, dispatched). Props are manually annotated using the JSDocs format and parsed using the
comment-parser
npm package.The generated TS definitions file defines a base class that stubs the interface of a Svelte component (following
svelte2tsx
) as consumed by the Svelte LSP:Each component extends the base class, overriding the base properties as necessary.
Component properties have a description and default value (if applicable).
Carbon icons are typed using the
typeof
operator:View the current generated definitions: types/index.d.ts
Changes
index.d.ts
has no props defined. #227 )prettier
to format generated types and.svelte
filescarbon-icons-svelte
to ^10.15.0 to consume library definitionstypescript
,@tsconfig/svelte
,comment-parser
,prettier
,prettier-plugin-svelte
Todo
rollup.generate
JavaScript APIcomment-parser
), slots, forwarded/dispatched eventsadd script to CI/publish flowNotes:
Usage of the Rollup JavaScript API could be avoided by incorporating the
generate-docs.js
script as a Rollup plugin.