Skip to content

Commit

Permalink
Add "context" typing to SvelteComponent constructor options (#6236)
Browse files Browse the repository at this point in the history
  • Loading branch information
qurafi committed Apr 24, 2021
1 parent ec25407 commit a39fc8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
* Avoid recreating DOM elements during hydration ([#6204](https://github.com/sveltejs/svelte/pull/6204))
* Add missing function overload for `derived` to allow explicitly setting an initial value for non-async derived stores ([#6172](https://github.com/sveltejs/svelte/pull/6172))
* Pass full markup source to script/style preprocessors ([#6169](https://github.com/sveltejs/svelte/pull/6169))
* Add "context" typing to SvelteComponent constructor options ([#6236](https://github.com/sveltejs/svelte/pull/6236))

## 3.37.0

Expand Down
34 changes: 15 additions & 19 deletions src/runtime/internal/dev.ts
Expand Up @@ -104,6 +104,16 @@ export interface SvelteComponentDev {
$destroy(): void;
[accessor: string]: any;
}
interface IComponentOptions {
target: Element;
anchor?: Element;
props?: Props;
context?: Map<any, any>;
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

0 comments on commit a39fc8d

Please sign in to comment.