fix(types): generate types for dist-custom-elements #3270
Merged
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.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm test
) were run locally and passednpm run test.karma.prod
) were run locally and passednpm run prettier
) was run locally and passedPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Type declarations are not created for users of the
dist-custom-elements
output target,unless they also provide the
dist
output target as wellGitHub Issue Number: N/A
What is the new behavior?
Commit 1
this commit introduces a new experimental flag,
generateTypeDeclarations
on thedist-custom-elements
output target.when enabled, it allows a user to generate type declaration files for
their stencil project (that uses
dist-custom-elements
) without alsospecifying the
dist
output target.this experimental flag generates types in the
dist/types
directory.this destination is not configurable at this time to better understand
the needs of users for generating these types
Commit 2
this commit adds jsdoc, clarifying comments, and minor type updates to
the codebase. this work was completed while working through adding
generateTypeDeclarations
to thedist-custom-elements
output target,but was split into a separate commit as to not detract from the work
being completed.
Does this introduce a breaking change?
Testing
Unit tests have been added to ensure that validating a
dist-custom-elements
output target returns the expected result. For these tests, I followed patterns existing in similar tests. While it may not be how I'd personally write them, i think maintaining consistency is more important in this matter, especially as we try to add new tests like theseNext, I generated a stencil project to serve as the foundation for a few manual tests (tested with Stencil v2.14.1):
npm init stencil component test-types
.By default, the Stencil CLI generates a Stencil config with the following:
I ran
npm run build
- then took this branch and installed it on said project and rannpm run build
again (without modifying my stencil config). I diffed thedist
directory from both builds, and saw minimal differences (stencil versions and one typo fix):.
Then, I modified my Stencil config for
dist-custom-elements
and removeddist
:I then diff'ed this against the previous
dist
generated, and verified that the custom-elements contents were found in bothdist
directories, and unnecessary files were not in my newly generateddist
:Finally, I modified my stencil config one last time to specify a custom output directory for
dist-custom-elements
. One more diff shows that the paths are set correctly for this build:{ outputTargets: [ { type: 'dist-custom-elements', generateTypeDeclarations: true, + dir: 'custom-elements-specified-dir' } ] }
Other information
Documentation PR: ionic-team/stencil-site#845