From c5594717ab1d31cb1bee44939061cc9bee2040a6 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Thu, 23 Feb 2023 08:11:01 +0100 Subject: [PATCH] fix types --- src/runtime/internal/dom.ts | 20 +++---- src/runtime/internal/lifecycle.ts | 4 ++ src/runtime/internal/utils.ts | 2 +- .../runtime/internal/lifecyle.test-types.ts | 56 ++++++++++--------- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index f45e60cfef..e2ef368cf1 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -350,15 +350,9 @@ export function set_svg_attributes(node: Element & ElementCSSInlineStyle, attrib } } -export function set_custom_element_data_map(node, data_map: Record) { +export function set_custom_element_data_map(node: Element, data_map: Record) { Object.keys(data_map).forEach((key) => { - set_custom_element_data(node, key, data_map[key]); - }); -} - -export function set_custom_element_data_map(node, data_map: Record) { - Object.keys(data_map).forEach((key) => { - set_custom_element_data(node, key, data_map[key]); + set_custom_element_data(node, key, data_map[key] as TODO); }); } @@ -548,7 +542,8 @@ export function claim_html_tag(nodes: ChildNodeArray, is_svg: boolean) { const start_index = find_comment(nodes, 'HTML_TAG_START', 0); const end_index = find_comment(nodes, 'HTML_TAG_END', start_index); if (start_index === end_index) { - return new HtmlTagHydration(undefined, is_svg); + // @ts-expect-error `HtmlTagHydration` does not expect a second parameter + return new HtmlTagHydration(undefined, is_svg); } init_claim_info(nodes); @@ -560,6 +555,7 @@ export function claim_html_tag(nodes: ChildNodeArray, is_svg: boolean) { n.claim_order = (nodes.claim_info as TODO).total_claimed; (nodes.claim_info as TODO).total_claimed += 1; } + // @ts-expect-error `HtmlTagHydration` does not expect a second parameter return new HtmlTagHydration(claimed_nodes, is_svg); } @@ -779,8 +775,8 @@ export class HtmlTagHydration extends HtmlTag { // hydration claimed nodes l: ChildNode[] | void; - constructor(claimed_nodes?: ChildNode[], is_svg: boolean = false) { - super(is_svg); + constructor(claimed_nodes?: ChildNode[]) { + super(); this.e = this.n = null; this.l = claimed_nodes; } @@ -814,6 +810,6 @@ export function get_custom_elements_slots(element: HTMLElement) { return result; } -export function construct_svelte_component(component, props) { +export function construct_svelte_component(component: TODO, props: Record) { return new component(props); } diff --git a/src/runtime/internal/lifecycle.ts b/src/runtime/internal/lifecycle.ts index 503055201a..7a6fac2c69 100644 --- a/src/runtime/internal/lifecycle.ts +++ b/src/runtime/internal/lifecycle.ts @@ -56,6 +56,10 @@ export function onDestroy(fn: () => any) { get_current_component().$$.on_destroy.push(fn); } +export interface DispatchOptions { + cancelable?: boolean; +} + /** * Creates an event dispatcher that can be used to dispatch [component events](/docs#template-syntax-component-directives-on-eventname). * Event dispatchers are functions that can take two arguments: `name` and `detail`. diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index b4c5898f3d..79c3ccba42 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -1,5 +1,5 @@ import { Readable, Subscriber, Invalidator, Writable } from 'svelte/store'; -import { SvelteComponent } from '..'; +import { SvelteComponent } from '../index.js'; export function noop() { } diff --git a/test/types/runtime/internal/lifecyle.test-types.ts b/test/types/runtime/internal/lifecyle.test-types.ts index 6190f675a5..6a3ebdd666 100644 --- a/test/types/runtime/internal/lifecyle.test-types.ts +++ b/test/types/runtime/internal/lifecyle.test-types.ts @@ -1,33 +1,35 @@ -import { createEventDispatcher } from '$runtime/internal/lifecycle'; +// TODO: enable those tests when #7224 got merged -const dispatch = createEventDispatcher<{ - loaded: never - change: string - valid: boolean - optional: number | null -}>(); +// import { createEventDispatcher } from '$runtime/internal/lifecycle'; -// @ts-expect-error: dispatch invalid event -dispatch('some-event'); +// const dispatch = createEventDispatcher<{ +// loaded: never +// change: string +// valid: boolean +// optional: number | null +// }>(); -dispatch('loaded'); -// @ts-expect-error: no detail accepted -dispatch('loaded', 123); +// // @ts-expect-error: dispatch invalid event +// dispatch('some-event'); -// @ts-expect-error: detail not provided -dispatch('change'); -dispatch('change', 'string'); -// @ts-expect-error: wrong type of detail -dispatch('change', 123); -// @ts-expect-error: wrong type of detail -dispatch('change', undefined); +// dispatch('loaded'); +// // @ts-expect-error: no detail accepted +// dispatch('loaded', 123); -dispatch('valid', true); -// @ts-expect-error: wrong type of detail -dispatch('valid', 'string'); +// // @ts-expect-error: detail not provided +// dispatch('change'); +// dispatch('change', 'string'); +// // @ts-expect-error: wrong type of detail +// dispatch('change', 123); +// // @ts-expect-error: wrong type of detail +// dispatch('change', undefined); -dispatch('optional'); -dispatch('optional', 123); -dispatch('optional', null); -// @ts-expect-error: wrong type of optional detail -dispatch('optional', 'string'); +// dispatch('valid', true); +// // @ts-expect-error: wrong type of detail +// dispatch('valid', 'string'); + +// dispatch('optional'); +// dispatch('optional', 123); +// dispatch('optional', null); +// // @ts-expect-error: wrong type of optional detail +// dispatch('optional', 'string');