From a8eeb7fb7d0477ddb1a09fc1f80353a4658cdb6f Mon Sep 17 00:00:00 2001 From: Mohammed Al qurafi <15172611+mhmd-22@users.noreply.github.com> Date: Sat, 24 Apr 2021 07:01:13 +0300 Subject: [PATCH 1/4] Add "context" typing on SvelteComponent class --- src/runtime/internal/dev.ts | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index 99ff067474dd..bb73da97aa1e 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -104,6 +104,16 @@ export interface SvelteComponentDev { $destroy(): void; [accessor: string]: any; } +interface IComponentOptions { + target: Element; + anchor?: Element; + props?: Props; + context: Record; + hydrate?: boolean; + intro?: boolean; + $$inline?: boolean; +} + /** * Base class for Svelte components with some minor dev-enhancements. Used when dev=true. */ @@ -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"); } @@ -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`: @@ -193,7 +196,7 @@ export interface SvelteComponentTyped< * * * ``` - * + * * #### Why not make this part of `SvelteComponent(Dev)`? * Because * ```ts @@ -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); } } From 1b7415d18a2f0a0e1be1274605d2a9782f28aef5 Mon Sep 17 00:00:00 2001 From: Mohammed Al qurafi <15172611+mhmd-22@users.noreply.github.com> Date: Sat, 24 Apr 2021 10:14:17 +0300 Subject: [PATCH 2/4] Make "context" type optional --- src/runtime/internal/dev.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index bb73da97aa1e..86f225551b71 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -108,7 +108,7 @@ interface IComponentOptions { target: Element; anchor?: Element; props?: Props; - context: Record; + context?: Record; hydrate?: boolean; intro?: boolean; $$inline?: boolean; From a81474a399fa2ea15d8d6ba47bd06a141bdd3efc Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Sat, 24 Apr 2021 15:57:18 +0200 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85281d4326d7..27812b982e6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 470ff6b02405d05dd5f5af62b2085b3c17672cc2 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Sat, 24 Apr 2021 15:58:28 +0200 Subject: [PATCH 4/4] Context is a map of any key/value kind --- src/runtime/internal/dev.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/internal/dev.ts b/src/runtime/internal/dev.ts index 86f225551b71..8e67b0f61b0b 100644 --- a/src/runtime/internal/dev.ts +++ b/src/runtime/internal/dev.ts @@ -108,7 +108,7 @@ interface IComponentOptions { target: Element; anchor?: Element; props?: Props; - context?: Record; + context?: Map; hydrate?: boolean; intro?: boolean; $$inline?: boolean;