Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTMLElementTagNameMap Part 2 - add create mapping and checker script #5139

Closed

Conversation

awikkerink
Copy link
Contributor

@awikkerink awikkerink commented Nov 10, 2024

This adds the ability to include a mappings.d.ts file, which allows an IDE with lit-ts-plugin installed to have typings for basic querySelector calls, and getElementByTagName calls. This also allows a project that is using typescript to type the core elements by referencing the mapped type

See https://github.com/BrightspaceUI/core/pull/5187/files#diff-cbc0e7a7d8e718c3c30b3003face1bc0bcfe98dcd79f3e4024fd270bda4c71d6 for what the final result should look like.

Also see
#5141
#5140

Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-5139/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

type LitElementConstructor = Constructor<{}>;
type LitElementClassType = Constructor<{}>;
type ReactiveElementConstructor = Constructor<{}>;
type ReactiveElementClassType = Constructor<{}>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typing all the template types to Constructor<{}> so that the errors are pushed to the check-html-element-tag-types.ts file

"strictFunctionTypes": false,
"moduleResolution": "bundler",
"maxNodeModuleJsDepth": 3,
"skipLibCheck": true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip errors in *.d.ts files

"strict": true,
"strictFunctionTypes": false,
"moduleResolution": "bundler",
"maxNodeModuleJsDepth": 3,
Copy link
Contributor Author

@awikkerink awikkerink Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,14 @@
/** Generated from {@link ../tools/create-mapping.sh} */
import { LitElement } from 'lit';
Copy link
Contributor Author

@awikkerink awikkerink Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is needed to extend the HTMLElementTagNameMap instead of defining it. Not sure if there is a better way to do this.

@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch 2 times, most recently from 0c76e6c to 6acaee2 Compare November 13, 2024 15:23
jsconfig.json Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsconfig.json is something that IDEs will pick up and use to add typing information.

declare global {
interface HTMLElementTagNameMap {
// Components with export class...extends LitElement
'd2l-build-info': import('../index.js').BuildInfo;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just starting with d2l-build-info as a proof of concept. Once the other PRs: #5140, #5141 are merged, the mapping.d.ts can be rebuilt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this, a CI step can be created to automatically update the mapping as needed. Then, adding new components to the map should be very simple. Just add an export or @typedef, then a PR will automatically be created to add it, and the lint step will ensure that the mixins are being used correctly.

@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch 2 times, most recently from 05e2774 to 77821e9 Compare November 18, 2024 20:25
@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch 2 times, most recently from a2eb685 to ce2d1ac Compare November 21, 2024 15:14
@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch 3 times, most recently from 35524ca to 32c0149 Compare December 1, 2024 03:03
@awikkerink awikkerink marked this pull request as ready for review December 2, 2024 14:10
@awikkerink awikkerink requested a review from a team as a code owner December 2, 2024 14:10
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Dec 3, 2024

PR #5188 created to update mapping.d.ts.

--edit
PR #5189 created for CI

@github-actions github-actions bot mentioned this pull request Dec 3, 2024
@awikkerink awikkerink mentioned this pull request Dec 3, 2024
Copy link
Contributor

github-actions bot commented Dec 3, 2024

PR #5190 created to update mapping.d.ts.

@github-actions github-actions bot mentioned this pull request Dec 6, 2024
@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch from b7c8c0e to 90ad388 Compare December 6, 2024 19:58
Copy link
Contributor

github-actions bot commented Dec 6, 2024

PR #5215 created to update mapping.d.ts. See https://github.com/BrightspaceUI/core?tab=readme-ov-file#mappingdts-troubleshooting for troubleshooting errors

@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch from 90ad388 to f1d225a Compare December 9, 2024 18:02
@github-actions github-actions bot mentioned this pull request Dec 9, 2024
Copy link
Contributor

github-actions bot commented Dec 9, 2024

PR #5220 created to update mapping.d.ts. See https://github.com/BrightspaceUI/core?tab=readme-ov-file#mappingdts-troubleshooting for troubleshooting errors

@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch from f1d225a to 1d532ee Compare December 11, 2024 14:13
Copy link
Contributor

PR #5227 created to update mapping.d.ts. See https://github.com/BrightspaceUI/core?tab=readme-ov-file#mappingdts-troubleshooting for troubleshooting errors

@github-actions github-actions bot mentioned this pull request Dec 11, 2024
awikkerink added a commit that referenced this pull request Dec 11, 2024
@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch from e791355 to 4516b1a Compare December 11, 2024 20:20
@awikkerink awikkerink force-pushed the awikkerink/inspiration-add-create-mapping-script branch from 4516b1a to 1b73b1b Compare December 12, 2024 14:42
@awikkerink
Copy link
Contributor Author

Closing, as the usefulness of HtmlElementTagNameMap is not very great, and adds a higher maintenance load on Nimbus

@awikkerink awikkerink closed this Dec 16, 2024
@awikkerink awikkerink deleted the awikkerink/inspiration-add-create-mapping-script branch December 16, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant