From f4b1508eb58550b71802f59532025ff198cdb011 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Tue, 1 Oct 2024 22:43:41 -0400 Subject: [PATCH] fix(svelte5): ensure typings are actually included in the module (#402) --- package.json | 2 +- src/component-types.d.ts | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 3601cd8..192560d 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "types": "svelte-check", "types:legacy": "svelte-check --tsconfig tsconfig.legacy.json", "validate": "npm-run-all test:vitest:* test:jest types build", - "build": "tsc -p tsconfig.build.json", + "build": "tsc -p tsconfig.build.json && cp src/component-types.d.ts types", "contributors:add": "all-contributors add", "contributors:generate": "all-contributors generate", "preview-release": "./scripts/preview-release" diff --git a/src/component-types.d.ts b/src/component-types.d.ts index a349597..9df84c2 100644 --- a/src/component-types.d.ts +++ b/src/component-types.d.ts @@ -1,11 +1,14 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import type * as Svelte from 'svelte' -// eslint-disable-next-line @typescript-eslint/no-explicit-any type IS_MODERN_SVELTE = any extends Svelte.Component ? false : true /** A compiled, imported Svelte component. */ -export type Component

= IS_MODERN_SVELTE extends true - ? Svelte.Component

| Svelte.SvelteComponent

+export type Component< + P extends Record, + E extends Record, +> = IS_MODERN_SVELTE extends true + ? Svelte.Component | Svelte.SvelteComponent

: Svelte.SvelteComponent

/** @@ -19,7 +22,7 @@ export type ComponentType = C extends Svelte.SvelteComponent : C /** The props of a component. */ -export type Props = Svelte.ComponentProps +export type Props> = Svelte.ComponentProps /** * The exported fields of a component. @@ -29,7 +32,7 @@ export type Props = Svelte.ComponentProps */ export type Exports = C extends Svelte.SvelteComponent ? C - : C extends Svelte.Component + : C extends Svelte.Component ? E : never @@ -38,6 +41,7 @@ export type Exports = C extends Svelte.SvelteComponent * * In Svelte 4, these are the options passed to the component constructor. */ -export type MountOptions = IS_MODERN_SVELTE extends true - ? Parameters, Exports>>[1] - : Svelte.ComponentConstructorOptions> +export type MountOptions> = + IS_MODERN_SVELTE extends true + ? Parameters, Exports>>[1] + : Svelte.ComponentConstructorOptions>