Skip to content

fix: ensure types are easier to follow for TypeScript #13140

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

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/metal-cameras-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure types are easier to follow for TypeScript
11 changes: 11 additions & 0 deletions packages/svelte/scripts/generate-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@ if (bad_links.length > 0) {

process.exit(1);
}

if (types.includes('\texport { ')) {
// eslint-disable-next-line no-console
console.error(
`The generated types file should not contain 'export { ... }' statements. ` +
`TypeScript is bad at following these: when creating d.ts files through @sveltejs/package, and one of these types is used, ` +
`TypeScript will likely fail at generating a d.ts file. ` +
`To prevent this, do 'export interface Foo {}' instead of 'interface Foo {}' and then 'export { Foo }'`
);
process.exit(1);
}
25 changes: 0 additions & 25 deletions packages/svelte/src/reactivity/index-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,3 @@ export { SvelteSet } from './set.js';
export { SvelteMap } from './map.js';
export { SvelteURL } from './url.js';
export { SvelteURLSearchParams } from './url-search-params.js';

/** @deprecated Use `SvelteDate` instead */
export function Date() {
throw new Error('Date has been removed, use SvelteDate instead.');
}

/** @deprecated Use `SvelteSet` instead */
export function Set() {
throw new Error('Set has been removed, use SvelteSet instead.');
}

/** @deprecated Use `SvelteMap` instead */
export function Map() {
throw new Error('Map has been removed, use SvelteMap instead.');
}

/** @deprecated Use `SvelteURL` instead */
export function URL() {
throw new Error('URL has been removed, use SvelteURL instead.');
}

/** @deprecated Use `SvelteURLSearchParams` instead */
export function URLSearchParams() {
throw new Error('URLSearchParams has been removed, use SvelteURLSearchParams instead.');
}
25 changes: 0 additions & 25 deletions packages/svelte/src/reactivity/index-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,3 @@ export const SvelteSet = globalThis.Set;
export const SvelteMap = globalThis.Map;
export const SvelteURL = globalThis.URL;
export const SvelteURLSearchParams = globalThis.URLSearchParams;

/** @deprecated Use `SvelteDate` instead */
export function Date() {
throw new Error('Date has been removed, use SvelteDate instead.');
}

/** @deprecated Use `SvelteSet` instead */
export function Set() {
throw new Error('Set has been removed, use SvelteSet instead.');
}

/** @deprecated Use `SvelteMap` instead */
export function Map() {
throw new Error('Map has been removed, use SvelteMap instead.');
}

/** @deprecated Use `SvelteURL` instead */
export function URL() {
throw new Error('URL has been removed, use SvelteURL instead.');
}

/** @deprecated Use `SvelteURLSearchParams` instead */
export function URLSearchParams() {
throw new Error('URLSearchParams has been removed, use SvelteURLSearchParams instead.');
}
14 changes: 6 additions & 8 deletions packages/svelte/src/store/public.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** Callback to inform of a value updates. */
type Subscriber<T> = (value: T) => void;
export type Subscriber<T> = (value: T) => void;

/** Unsubscribes from value updates. */
type Unsubscriber = () => void;
export type Unsubscriber = () => void;

/** Callback to update a value. */
type Updater<T> = (value: T) => T;
export type Updater<T> = (value: T) => T;

/**
* Start and stop notification callbacks.
Expand All @@ -16,13 +16,13 @@ type Updater<T> = (value: T) => T;
* @returns {void | (() => void)} Optionally, a cleanup function that is called when the last remaining
* subscriber unsubscribes.
*/
type StartStopNotifier<T> = (
export type StartStopNotifier<T> = (
set: (value: T) => void,
update: (fn: Updater<T>) => void
) => void | (() => void);

/** Readable interface for subscribing. */
interface Readable<T> {
export interface Readable<T> {
/**
* Subscribe on value changes.
* @param run subscription callback
Expand All @@ -32,7 +32,7 @@ interface Readable<T> {
}

/** Writable interface for both updating and subscribing. */
interface Writable<T> extends Readable<T> {
export interface Writable<T> extends Readable<T> {
/**
* Set value and inform subscribers.
* @param value to set
Expand All @@ -46,6 +46,4 @@ interface Writable<T> extends Readable<T> {
update(this: void, updater: Updater<T>): void;
}

export { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable };

export * from './index-client.js';
30 changes: 9 additions & 21 deletions packages/svelte/src/transition/public.d.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
type EasingFunction = (t: number) => number;
export type EasingFunction = (t: number) => number;

interface TransitionConfig {
export interface TransitionConfig {
delay?: number;
duration?: number;
easing?: EasingFunction;
css?: (t: number, u: number) => string;
tick?: (t: number, u: number) => void;
}

interface BlurParams {
export interface BlurParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
amount?: number | string;
opacity?: number;
}

interface FadeParams {
export interface FadeParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
}

interface FlyParams {
export interface FlyParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
Expand All @@ -31,44 +31,32 @@ interface FlyParams {
opacity?: number;
}

interface SlideParams {
export interface SlideParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
axis?: 'x' | 'y';
}

interface ScaleParams {
export interface ScaleParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
start?: number;
opacity?: number;
}

interface DrawParams {
export interface DrawParams {
delay?: number;
speed?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
}

interface CrossfadeParams {
export interface CrossfadeParams {
delay?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
}

export {
EasingFunction,
TransitionConfig,
BlurParams,
FadeParams,
FlyParams,
SlideParams,
ScaleParams,
DrawParams,
CrossfadeParams
};

export * from './index.js';
46 changes: 18 additions & 28 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,16 +1700,6 @@ declare module 'svelte/motion' {
}

declare module 'svelte/reactivity' {
/** @deprecated Use `SvelteDate` instead */
function Date_1(): void;
/** @deprecated Use `SvelteSet` instead */
function Set_1(): void;
/** @deprecated Use `SvelteMap` instead */
function Map_1(): void;
/** @deprecated Use `SvelteURL` instead */
function URL_1(): void;
/** @deprecated Use `SvelteURLSearchParams` instead */
function URLSearchParams_1(): void;
export class SvelteDate extends Date {

constructor(...params: any[]);
Expand Down Expand Up @@ -1740,7 +1730,7 @@ declare module 'svelte/reactivity' {
#private;
}

export { Date_1 as Date, Set_1 as Set, Map_1 as Map, URL_1 as URL, URLSearchParams_1 as URLSearchParams };
export {};
}

declare module 'svelte/server' {
Expand Down Expand Up @@ -1777,13 +1767,13 @@ declare module 'svelte/server' {

declare module 'svelte/store' {
/** Callback to inform of a value updates. */
type Subscriber<T> = (value: T) => void;
export type Subscriber<T> = (value: T) => void;

/** Unsubscribes from value updates. */
type Unsubscriber = () => void;
export type Unsubscriber = () => void;

/** Callback to update a value. */
type Updater<T> = (value: T) => T;
export type Updater<T> = (value: T) => T;

/**
* Start and stop notification callbacks.
Expand All @@ -1794,13 +1784,13 @@ declare module 'svelte/store' {
* @returns Optionally, a cleanup function that is called when the last remaining
* subscriber unsubscribes.
*/
type StartStopNotifier<T> = (
export type StartStopNotifier<T> = (
set: (value: T) => void,
update: (fn: Updater<T>) => void
) => void | (() => void);

/** Readable interface for subscribing. */
interface Readable<T> {
export interface Readable<T> {
/**
* Subscribe on value changes.
* @param run subscription callback
Expand All @@ -1810,7 +1800,7 @@ declare module 'svelte/store' {
}

/** Writable interface for both updating and subscribing. */
interface Writable<T> extends Readable<T> {
export interface Writable<T> extends Readable<T> {
/**
* Set value and inform subscribers.
* @param value to set
Expand Down Expand Up @@ -1882,35 +1872,35 @@ declare module 'svelte/store' {
type StoresValues<T> =
T extends Readable<infer U> ? U : { [K in keyof T]: T[K] extends Readable<infer U> ? U : never };

export { Subscriber, Unsubscriber, Updater, StartStopNotifier, Readable, Writable };
export {};
}

declare module 'svelte/transition' {
type EasingFunction = (t: number) => number;
export type EasingFunction = (t: number) => number;

interface TransitionConfig {
export interface TransitionConfig {
delay?: number;
duration?: number;
easing?: EasingFunction;
css?: (t: number, u: number) => string;
tick?: (t: number, u: number) => void;
}

interface BlurParams {
export interface BlurParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
amount?: number | string;
opacity?: number;
}

interface FadeParams {
export interface FadeParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
}

interface FlyParams {
export interface FlyParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
Expand All @@ -1919,29 +1909,29 @@ declare module 'svelte/transition' {
opacity?: number;
}

interface SlideParams {
export interface SlideParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
axis?: 'x' | 'y';
}

interface ScaleParams {
export interface ScaleParams {
delay?: number;
duration?: number;
easing?: EasingFunction;
start?: number;
opacity?: number;
}

interface DrawParams {
export interface DrawParams {
delay?: number;
speed?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
}

interface CrossfadeParams {
export interface CrossfadeParams {
delay?: number;
duration?: number | ((len: number) => number);
easing?: EasingFunction;
Expand Down Expand Up @@ -1997,7 +1987,7 @@ declare module 'svelte/transition' {
key: any;
}) => () => TransitionConfig];

export { EasingFunction, TransitionConfig, BlurParams, FadeParams, FlyParams, SlideParams, ScaleParams, DrawParams, CrossfadeParams };
export {};
}

declare module 'svelte/events' {
Expand Down