-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Example of TypeScript Types in file index.d.ts for a web-component. #173
Comments
Hi @riccardoscalco. Your question is more general, and not strictly related to hybrids, but to defining custom elements for the TS. I suppose, that there is no one the best way to do that, but I can recommend looking for some examples. One of the time elements from GitHub produces following export default class LocalTimeElement extends ExtendedTimeElement {
attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
getFormattedDate(): string | undefined;
}
declare global {
interface Window {
LocalTimeElement: typeof LocalTimeElement;
}
interface HTMLElementTagNameMap {
'local-time': LocalTimeElement;
}
} The above definition assumes, that this custom element is also registered in For the component built with hybrids, follow typescript guides for putting properties into the class, and create something like this: class MyElement extends HTMLElement {
propOne: string;
propTwo: string;
}
declare global {
interface Window {
MyElement: typeof MyElement; // if you register your element in global scope
}
interface HTMLElementTagNameMap {
'my-element': LocalTimeElement;
}
} There is also a tool https://github.com/runem/web-component-analyzer, which describes how you can add comments/metadata for better IDE completion. |
I'm not sure, but it might be required to add a declare module "@nextbitlabs/trend-line" {
...
} For testing the best way is to set up a simple project, which uses TS and import your module by the relative path from the disk |
Thanks for the precious suggestions, I give it a try! |
Share your result when it will be ready :) |
An update: I managed to automatically generate file File
The automatically generated
I am not sure this |
Your automatically generated Try to follow what I wrote in the last comments. |
Feel free to re-open if you need more help with the subject. |
Hi, recently I wrote a web component with hybrids. The package score in skypack.dev shows that TypeScript Types are missing in the package.
I am very new to TypeScript and I do not know exactly how to create the
index.d.ts
file for the web component. I found this page in hybrids docs, where there is an example of how to use TypeScript with hybrids.However, I prefer to keep the code in plain JS and create the file
index.d.ts
for the user-base that works with TypeScript.Could you please provide an example of the file
index.d.ts
related to a web component created with hybrids?Thanks in advance.
The text was updated successfully, but these errors were encountered: