Skip to content

Commit 76edf2d

Browse files
authored
(doc) faq for attribute/event type errosr
1 parent 68df202 commit 76edf2d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/preprocessors/typescript.md

+21
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,24 @@ You may need to set `baseUrl` in `tsconfig.json` at the project root to include
120120
}
121121
}
122122
```
123+
124+
### I'm using an attribute/event on a DOM element and it throws a type error
125+
126+
If it's a non-experimental standard attribute/event, this may very well be a missing typing from our [JSX typings](https://github.com/sveltejs/language-tools/blob/master/packages/svelte2tsx/svelte-jsx.d.ts). In that case, you are welcome to open an issue and/or a PR fixing it.
127+
128+
In case this is a custom or experimental attribute/event, you can enhance the typings like this:
129+
Create a `additional-svelte-jsx.d.ts` file:
130+
131+
```ts
132+
declare namespace svelte.JSX {
133+
interface HTMLAttributes<T> {
134+
// If you want to use on:beforeinstallprompt
135+
onbeforeinstallprompt?: (event: any) => any;
136+
// If you want to use myCustomAttribute={..} (note: all lowercase)
137+
mycustomattribute?: any;
138+
// You can replace any with something more specific if you like
139+
}
140+
}
141+
```
142+
143+
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.

0 commit comments

Comments
 (0)