@ -195,7 +195,13 @@ Using it together with dynamic components to restrict what kinds of component ca
<DynamicComponentprop="foo"/>
<DynamicComponentprop="foo"/>
```
```
Closely related to the `Component` type is the `ComponentProps` type which extracts the properties a component expects.
> [!LEGACY] In Svelte 4, components were of type `SvelteComponent`
## Component helper types
### ComponentProps
`ComponentProps` extracts the properties a component expects.
```ts
```ts
import type { Component, ComponentProps } from 'svelte';
import type { Component, ComponentProps } from 'svelte';
@ -211,6 +217,21 @@ function withProps<TComponent extends Component<any>>(
withProps(MyComponent, { foo: 'bar' });
withProps(MyComponent, { foo: 'bar' });
```
```
### ComponentExports
`ComponentExports` extracts the exports of a component, in other words you can use it to declare its instance type:
```svelte
<scriptlang="ts">
import type { ComponentExports } from 'svelte';
import { Component } from './Component.svelte';
let component: ComponentExports<typeofComponent>;
</script>
<Componentbind:this={component}/>
```
## Enhancing built-in DOM types
## Enhancing built-in DOM types
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.
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.
The two utility types `ComponentEvents` and `ComponentType` are also deprecated. `ComponentEvents` is obsolete because events are defined as callback props now, and `ComponentType` is obsolete because the new `Component` type is the component type already (e.g. `ComponentType<SvelteComponent<{ prop: string }>>` == `Component<{ prop: string }>`).
The two utility types `ComponentEvents` and `ComponentType` are also deprecated. `ComponentEvents` is obsolete because events are defined as callback props now, and `ComponentType` is obsolete because the new `Component` type is the component type already (e.g. `ComponentType<SvelteComponent<{ prop: string }>>` == `Component<{ prop: string }>`).