Skip to content

Commit

Permalink
fix: export temporary LegacyComponentType (#14256) (#14257)
Browse files Browse the repository at this point in the history
closes  #14256

helps TypeScript when generating dts files to not fail
  • Loading branch information
Theo-Steiner authored Nov 22, 2024
1 parent 0469008 commit e721d96
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-mayflies-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: provide temporary `LegacyComponentType`
14 changes: 3 additions & 11 deletions packages/svelte/src/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
declare module '*.svelte' {
// use prettier-ignore for a while because of https://github.com/sveltejs/language-tools/commit/026111228b5814a9109cc4d779d37fb02955fb8b
// prettier-ignore
import { SvelteComponent, Component, type ComponentConstructorOptions } from 'svelte'

// Support using the component as both a class and function during the transition period
// prettier-ignore
interface ComponentType {
(
...args: Parameters<Component<Record<string, any>>>
): ReturnType<Component<Record<string, any>, Record<string, any>>>
new (o: ComponentConstructorOptions): SvelteComponent
}
const Comp: ComponentType;
import { SvelteComponent } from 'svelte'
import { LegacyComponentType } from 'svelte/legacy';
const Comp: LegacyComponentType;
type Comp = SvelteComponent;
export default Comp;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/svelte/src/legacy/legacy-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export function asClassComponent(component) {
};
}

/**
* Support using the component as both a class and function during the transition period
* @typedef {{new (o: ComponentConstructorOptions): SvelteComponent;(...args: Parameters<Component<Record<string, any>>>): ReturnType<Component<Record<string, any>, Record<string, any>>>;}} LegacyComponentType
*/

class Svelte4Component {
/** @type {any} */
#events;
Expand Down
21 changes: 10 additions & 11 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,13 @@ declare module 'svelte/legacy' {
* @deprecated Use this only as a temporary solution to migrate your automatically delegated events in Svelte 5.
*/
export function createBubbler(): (type: string) => (event: Event) => boolean;
/**
* Support using the component as both a class and function during the transition period
*/
export type LegacyComponentType = {
new (o: ComponentConstructorOptions): SvelteComponent;
(...args: Parameters<Component<Record<string, any>>>): ReturnType<Component<Record<string, any>, Record<string, any>>>;
};
/**
* Substitute for the `trusted` event modifier
* @deprecated
Expand Down Expand Up @@ -2308,17 +2315,9 @@ declare module 'svelte/types/compiler/interfaces' {
}declare module '*.svelte' {
// use prettier-ignore for a while because of https://github.com/sveltejs/language-tools/commit/026111228b5814a9109cc4d779d37fb02955fb8b
// prettier-ignore
import { SvelteComponent, Component, type ComponentConstructorOptions } from 'svelte'

// Support using the component as both a class and function during the transition period
// prettier-ignore
interface ComponentType {
(
...args: Parameters<Component<Record<string, any>>>
): ReturnType<Component<Record<string, any>, Record<string, any>>>
new (o: ComponentConstructorOptions): SvelteComponent
}
const Comp: ComponentType;
import { SvelteComponent } from 'svelte'
import { LegacyComponentType } from 'svelte/legacy';
const Comp: LegacyComponentType;
type Comp = SvelteComponent;
export default Comp;
}
Expand Down

0 comments on commit e721d96

Please sign in to comment.