You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: remove mention of deprecated way to enhance typings (#16416)
Since #9070 it's prefered to use the "enhance svelte elements" way of doing things. That's so long ago that we can now remove the other option from the docs, and eventually remove the backwards compatibility that still allows the old way of doing things.
Copy file name to clipboardExpand all lines: documentation/docs/07-misc/03-typescript.md
+10-23Lines changed: 10 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -254,43 +254,30 @@ To declare that a variable expects the constructor or instance type of a compone
254
254
255
255
Svelte provides a best effort of all the HTML DOM types that exist. Sometimes you may want to use experimental attributes or custom events coming from an action. In these cases, TypeScript will throw a type error, saying that it does not know these types. If it's a non-experimental standard attribute/event, this may very well be a missing typing from our [HTML typings](https://github.com/sveltejs/svelte/blob/main/packages/svelte/elements.d.ts). In that case, you are welcome to open an issue and/or a PR fixing it.
256
256
257
-
In case this is a custom or experimental attribute/event, you can enhance the typings like this:
// If you want to use the beforeinstallprompt event
269
-
onbeforeinstallprompt?: (event:any) =>any;
270
-
// If you want to use myCustomAttribute={..} (note: all lowercase)
271
-
mycustomattribute?:any; // You can replace any with something more specific if you like
272
-
}
273
-
}
274
-
```
275
-
276
-
Then make sure that `d.ts` file is referenced in your `tsconfig.json`. If it reads something like `"include": ["src/**/*"]` and your `d.ts` file is inside `src`, it should work. You may need to reload for the changes to take effect.
277
-
278
-
You can also declare the typings by augmenting the `svelte/elements` module like this:
257
+
In case this is a custom or experimental attribute/event, you can enhance the typings by augmenting the `svelte/elements` module like this:
// allows for more granular control over what element to add the typings to
269
+
// add a new global attribute that is available on all html elements
270
+
exportinterfaceHTMLAttributes<T> {
271
+
globalattribute?:string;
272
+
}
273
+
274
+
// add a new attribute for button elements
290
275
exportinterfaceHTMLButtonAttributes {
291
276
veryexperimentalattribute?:string;
292
277
}
293
278
}
294
279
295
280
export {}; // ensure this is not an ambient module, else types will be overridden instead of augmented
296
281
```
282
+
283
+
Then make sure that the `d.ts` file is referenced in your `tsconfig.json`. If it reads something like `"include": ["src/**/*"]` and your `d.ts` file is inside `src`, it should work. You may need to reload for the changes to take effect.
0 commit comments