Skip to content

Commit

Permalink
Revert "feat: add ComponentExports utility type (#13441)" (#14069)
Browse files Browse the repository at this point in the history
This reverts commit d93ad3b.
  • Loading branch information
Rich-Harris authored Oct 31, 2024
1 parent 4f80ab6 commit 2784fb1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 70 deletions.
5 changes: 0 additions & 5 deletions .changeset/rotten-cups-float.md

This file was deleted.

20 changes: 0 additions & 20 deletions packages/svelte/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,26 +237,6 @@ export type ComponentProps<Comp extends SvelteComponent | Component<any, any>> =
? Props
: never;

/**
* Convenience type to get the properties that given component exports.
*
* Example: Typing the `bind:this` for a component named `MyComponent`
* ```
* <script lang="ts">
* import MyComponent from '$lib/component';
* let component: ComponentExports<typeof MyComponent> | undefined = undefined;
* <script>
*
* <MyComponent bind:this={component} />
* ```
*/
export type ComponentExports<TComponent extends Component<any, any> | typeof SvelteComponent<any>> =
TComponent extends typeof SvelteComponent<any>
? InstanceType<TComponent>
: TComponent extends Component<any, infer TExports>
? TExports
: never;

/**
* @deprecated This type is obsolete when working with the new `Component` type.
*
Expand Down
26 changes: 1 addition & 25 deletions packages/svelte/tests/types/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
mount,
hydrate,
type Component,
type ComponentInternals,
type ComponentExports
type ComponentInternals
} from 'svelte';
import { render } from 'svelte/server';

Expand Down Expand Up @@ -181,16 +180,6 @@ render(NewComponent, {
}
});

const newComponentExports: ComponentExports<typeof NewComponent> = {
anExport: '',
$$events_def: null as any,
$$prop_def: null as any,
$$slot_def: null as any,
$set: null as any,
$destroy: null as any,
$on: null as any
};

// --------------------------------------------------------------------------- interop

const AsLegacyComponent = asClassComponent(newComponent);
Expand Down Expand Up @@ -348,19 +337,6 @@ render(functionComponent, {
}
});

const functionComponentExports: ComponentExports<typeof functionComponent> = {
foo: 'bar',
// @ts-expect-error
x: ''
};

type AdhocFunctionComponent = (a: unknown, b: { a: true }) => { foo: string };
const adhocFunctionComponentExport: ComponentExports<AdhocFunctionComponent> = {
foo: 'bar',
// @ts-expect-error
x: ''
};

// --------------------------------------------------------------------------- *.svelte components

// import from a nonexistent file to trigger the declare module '*.svelte' in ambient.d.ts
Expand Down
20 changes: 0 additions & 20 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,26 +234,6 @@ declare module 'svelte' {
? Props
: never;

/**
* Convenience type to get the properties that given component exports.
*
* Example: Typing the `bind:this` for a component named `MyComponent`
* ```
* <script lang="ts">
* import MyComponent from '$lib/component';
* let component: ComponentExports<typeof MyComponent> | undefined = undefined;
* <script>
*
* <MyComponent bind:this={component} />
* ```
*/
export type ComponentExports<TComponent extends Component<any, any> | typeof SvelteComponent<any>> =
TComponent extends typeof SvelteComponent<any>
? InstanceType<TComponent>
: TComponent extends Component<any, infer TExports>
? TExports
: never;

/**
* @deprecated This type is obsolete when working with the new `Component` type.
*
Expand Down

0 comments on commit 2784fb1

Please sign in to comment.