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

As a byproduct of #12239 some types were changed from being directly exported to indirectly exported. TypeScript is bad at following these types while generating d.ts files, so we can't do that. A check at the end of the types generation was added to prevent regressions in the future. Fixes #13128

Also removes the old types from `svelte/reactivity` which are deprecated for a while now.
pull/13145/head
Simon H 4 months ago committed by GitHub
parent d5da75d7c0
commit e1448f22a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure types are easier to follow for TypeScript

@ -60,3 +60,14 @@ if (bad_links.length > 0) {
process.exit(1); 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);
}

@ -3,28 +3,3 @@ export { SvelteSet } from './set.js';
export { SvelteMap } from './map.js'; export { SvelteMap } from './map.js';
export { SvelteURL } from './url.js'; export { SvelteURL } from './url.js';
export { SvelteURLSearchParams } from './url-search-params.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.');
}

@ -3,28 +3,3 @@ export const SvelteSet = globalThis.Set;
export const SvelteMap = globalThis.Map; export const SvelteMap = globalThis.Map;
export const SvelteURL = globalThis.URL; export const SvelteURL = globalThis.URL;
export const SvelteURLSearchParams = globalThis.URLSearchParams; 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.');
}

@ -1,11 +1,11 @@
/** Callback to inform of a value updates. */ /** Callback to inform of a value updates. */
type Subscriber<T> = (value: T) => void; export type Subscriber<T> = (value: T) => void;
/** Unsubscribes from value updates. */ /** Unsubscribes from value updates. */
type Unsubscriber = () => void; export type Unsubscriber = () => void;
/** Callback to update a value. */ /** Callback to update a value. */
type Updater<T> = (value: T) => T; export type Updater<T> = (value: T) => T;
/** /**
* Start and stop notification callbacks. * Start and stop notification callbacks.
@ -16,13 +16,13 @@ type Updater<T> = (value: T) => T;
* @returns {void | (() => void)} Optionally, a cleanup function that is called when the last remaining * @returns {void | (() => void)} Optionally, a cleanup function that is called when the last remaining
* subscriber unsubscribes. * subscriber unsubscribes.
*/ */
type StartStopNotifier<T> = ( export type StartStopNotifier<T> = (
set: (value: T) => void, set: (value: T) => void,
update: (fn: Updater<T>) => void update: (fn: Updater<T>) => void
) => void | (() => void); ) => void | (() => void);
/** Readable interface for subscribing. */ /** Readable interface for subscribing. */
interface Readable<T> { export interface Readable<T> {
/** /**
* Subscribe on value changes. * Subscribe on value changes.
* @param run subscription callback * @param run subscription callback
@ -32,7 +32,7 @@ interface Readable<T> {
} }
/** Writable interface for both updating and subscribing. */ /** 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. * Set value and inform subscribers.
* @param value to set * @param value to set
@ -46,6 +46,4 @@ interface Writable<T> extends Readable<T> {
update(this: void, updater: Updater<T>): void; update(this: void, updater: Updater<T>): void;
} }
export { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable };
export * from './index-client.js'; export * from './index-client.js';

@ -1,6 +1,6 @@
type EasingFunction = (t: number) => number; export type EasingFunction = (t: number) => number;
interface TransitionConfig { export interface TransitionConfig {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
@ -8,7 +8,7 @@ interface TransitionConfig {
tick?: (t: number, u: number) => void; tick?: (t: number, u: number) => void;
} }
interface BlurParams { export interface BlurParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
@ -16,13 +16,13 @@ interface BlurParams {
opacity?: number; opacity?: number;
} }
interface FadeParams { export interface FadeParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
} }
interface FlyParams { export interface FlyParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
@ -31,14 +31,14 @@ interface FlyParams {
opacity?: number; opacity?: number;
} }
interface SlideParams { export interface SlideParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
axis?: 'x' | 'y'; axis?: 'x' | 'y';
} }
interface ScaleParams { export interface ScaleParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
@ -46,29 +46,17 @@ interface ScaleParams {
opacity?: number; opacity?: number;
} }
interface DrawParams { export interface DrawParams {
delay?: number; delay?: number;
speed?: number; speed?: number;
duration?: number | ((len: number) => number); duration?: number | ((len: number) => number);
easing?: EasingFunction; easing?: EasingFunction;
} }
interface CrossfadeParams { export interface CrossfadeParams {
delay?: number; delay?: number;
duration?: number | ((len: number) => number); duration?: number | ((len: number) => number);
easing?: EasingFunction; easing?: EasingFunction;
} }
export {
EasingFunction,
TransitionConfig,
BlurParams,
FadeParams,
FlyParams,
SlideParams,
ScaleParams,
DrawParams,
CrossfadeParams
};
export * from './index.js'; export * from './index.js';

@ -1700,16 +1700,6 @@ declare module 'svelte/motion' {
} }
declare module 'svelte/reactivity' { 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 { export class SvelteDate extends Date {
constructor(...params: any[]); constructor(...params: any[]);
@ -1740,7 +1730,7 @@ declare module 'svelte/reactivity' {
#private; #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' { declare module 'svelte/server' {
@ -1777,13 +1767,13 @@ declare module 'svelte/server' {
declare module 'svelte/store' { declare module 'svelte/store' {
/** Callback to inform of a value updates. */ /** Callback to inform of a value updates. */
type Subscriber<T> = (value: T) => void; export type Subscriber<T> = (value: T) => void;
/** Unsubscribes from value updates. */ /** Unsubscribes from value updates. */
type Unsubscriber = () => void; export type Unsubscriber = () => void;
/** Callback to update a value. */ /** Callback to update a value. */
type Updater<T> = (value: T) => T; export type Updater<T> = (value: T) => T;
/** /**
* Start and stop notification callbacks. * Start and stop notification callbacks.
@ -1794,13 +1784,13 @@ declare module 'svelte/store' {
* @returns Optionally, a cleanup function that is called when the last remaining * @returns Optionally, a cleanup function that is called when the last remaining
* subscriber unsubscribes. * subscriber unsubscribes.
*/ */
type StartStopNotifier<T> = ( export type StartStopNotifier<T> = (
set: (value: T) => void, set: (value: T) => void,
update: (fn: Updater<T>) => void update: (fn: Updater<T>) => void
) => void | (() => void); ) => void | (() => void);
/** Readable interface for subscribing. */ /** Readable interface for subscribing. */
interface Readable<T> { export interface Readable<T> {
/** /**
* Subscribe on value changes. * Subscribe on value changes.
* @param run subscription callback * @param run subscription callback
@ -1810,7 +1800,7 @@ declare module 'svelte/store' {
} }
/** Writable interface for both updating and subscribing. */ /** 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. * Set value and inform subscribers.
* @param value to set * @param value to set
@ -1882,13 +1872,13 @@ declare module 'svelte/store' {
type StoresValues<T> = type StoresValues<T> =
T extends Readable<infer U> ? U : { [K in keyof T]: T[K] extends Readable<infer U> ? U : never }; 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' { declare module 'svelte/transition' {
type EasingFunction = (t: number) => number; export type EasingFunction = (t: number) => number;
interface TransitionConfig { export interface TransitionConfig {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
@ -1896,7 +1886,7 @@ declare module 'svelte/transition' {
tick?: (t: number, u: number) => void; tick?: (t: number, u: number) => void;
} }
interface BlurParams { export interface BlurParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
@ -1904,13 +1894,13 @@ declare module 'svelte/transition' {
opacity?: number; opacity?: number;
} }
interface FadeParams { export interface FadeParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
} }
interface FlyParams { export interface FlyParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
@ -1919,14 +1909,14 @@ declare module 'svelte/transition' {
opacity?: number; opacity?: number;
} }
interface SlideParams { export interface SlideParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
axis?: 'x' | 'y'; axis?: 'x' | 'y';
} }
interface ScaleParams { export interface ScaleParams {
delay?: number; delay?: number;
duration?: number; duration?: number;
easing?: EasingFunction; easing?: EasingFunction;
@ -1934,14 +1924,14 @@ declare module 'svelte/transition' {
opacity?: number; opacity?: number;
} }
interface DrawParams { export interface DrawParams {
delay?: number; delay?: number;
speed?: number; speed?: number;
duration?: number | ((len: number) => number); duration?: number | ((len: number) => number);
easing?: EasingFunction; easing?: EasingFunction;
} }
interface CrossfadeParams { export interface CrossfadeParams {
delay?: number; delay?: number;
duration?: number | ((len: number) => number); duration?: number | ((len: number) => number);
easing?: EasingFunction; easing?: EasingFunction;
@ -1997,7 +1987,7 @@ declare module 'svelte/transition' {
key: any; key: any;
}) => () => TransitionConfig]; }) => () => TransitionConfig];
export { EasingFunction, TransitionConfig, BlurParams, FadeParams, FlyParams, SlideParams, ScaleParams, DrawParams, CrossfadeParams }; export {};
} }
declare module 'svelte/events' { declare module 'svelte/events' {

Loading…
Cancel
Save