[feat] add convenience SvelteComponentConstructor type

Eases typing "this is a variable that expects a Svelte component constructor (of a certain shape)". Removes the need for SvelteComponentTyped to be an extra type so it can be deprecated in v4 and removed in v5, and SvelteComponent(Dev) can receive the same generic typings as SvelteComponetTyped in v4.
pull/6770/head
Simon Holthausen 5 years ago
parent dbbac2837e
commit 359b3ecf8c

@ -1,5 +1,9 @@
# Svelte changelog
## Unreleased
* Add `SvelteComponentConstructor` convenience type ([#6770](https://github.com/sveltejs/svelte/pull/6770))
## 3.43.0
* Use export map to expose no-op versions of lifecycle functions for SSR ([#6743](https://github.com/sveltejs/svelte/pull/6743))

@ -12,5 +12,6 @@ export {
tick,
createEventDispatcher,
SvelteComponentDev as SvelteComponent,
SvelteComponentTyped
SvelteComponentTyped,
SvelteComponentConstructor
} from 'svelte/internal';

@ -247,6 +247,22 @@ export class SvelteComponentTyped<
}
}
/**
* Convenience-type to represent a Svelte component constructor.
*
* Example:
* ```ts
import ASvelteComponent from './ASvelteComponent.svelte';
const ComponentClass: SvelteComponentConstructor = ASvelteComponent;
new ComponentClass(..);
```
*/
export type SvelteComponentConstructor<
Props extends Record<string, any> = any,
Events extends Record<string, any> = any,
Slots extends Record<string, any> = any
> = new (options: IComponentOptions<Props>) => SvelteComponentTyped<Props, Events, Slots>;
export function loop_guard(timeout) {
const start = Date.now();
return () => {

Loading…
Cancel
Save