Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "context" typing on SvelteComponent options #6236

Merged
merged 4 commits into from
Apr 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions src/runtime/internal/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ export interface SvelteComponentDev {
$destroy(): void;
[accessor: string]: any;
}
interface IComponentOptions {
target: Element;
anchor?: Element;
props?: Props;
context: Record<string, unknown>;
qurafi marked this conversation as resolved.
Show resolved Hide resolved
hydrate?: boolean;
intro?: boolean;
$$inline?: boolean;
}

/**
* Base class for Svelte components with some minor dev-enhancements. Used when dev=true.
*/
Expand All @@ -130,14 +140,7 @@ export class SvelteComponentDev extends SvelteComponent {
*/
$$slot_def: any;

constructor(options: {
target: Element;
anchor?: Element;
props?: Props;
hydrate?: boolean;
intro?: boolean;
$$inline?: boolean;
}) {
constructor(options: IComponentOptions) {
if (!options || (!options.target && !options.$$inline)) {
throw new Error("'target' is a required option");
}
Expand Down Expand Up @@ -174,9 +177,9 @@ export interface SvelteComponentTyped<
/**
* Base class to create strongly typed Svelte components.
* This only exists for typing purposes and should be used in `.d.ts` files.
*
*
* ### Example:
*
*
* You have component library on npm called `component-library`, from which
* you export a component called `MyComponent`. For Svelte+TypeScript users,
* you want to provide typings. Therefore you create a `index.d.ts`:
Expand All @@ -193,7 +196,7 @@ export interface SvelteComponentTyped<
* </script>
* <MyComponent foo={'bar'} />
* ```
*
*
* #### Why not make this part of `SvelteComponent(Dev)`?
* Because
* ```ts
Expand Down Expand Up @@ -229,14 +232,7 @@ export class SvelteComponentTyped<
*/
$$slot_def: Slots;

constructor(options: {
target: Element;
anchor?: Element;
props?: Props;
hydrate?: boolean;
intro?: boolean;
$$inline?: boolean;
}) {
constructor(options: IComponentOptions) {
super(options);
}
}
Expand Down