Skip to content

Commit e951ae3

Browse files
committed
tweak
1 parent 8451a79 commit e951ae3

File tree

4 files changed

+5
-26
lines changed

4 files changed

+5
-26
lines changed

packages/svelte/src/index.d.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ type WithBindings<T> = {
3030
[Key in keyof T]: Bindable<T[Key]>;
3131
};
3232

33-
type StripBindable<Props extends Record<string, any>> = {
34-
[Key in keyof Props]: Props[Key] extends Bindable<infer Value> ? Value : Props[Key];
35-
};
36-
3733
/**
3834
* Utility type for ensuring backwards compatibility on a type level:
3935
* - If there's a default slot, add 'children' to the props
@@ -97,7 +93,7 @@ export class SvelteComponent<
9793
* Does not exist at runtime.
9894
* ### DO NOT USE!
9995
* */
100-
$$prop_def: StripBindable<Props>; // Without PropsWithChildren: unnecessary, causes type bugs
96+
$$prop_def: RemoveBindable<Props>; // Without PropsWithChildren: unnecessary, causes type bugs
10197
/**
10298
* For type checking capabilities only.
10399
* Does not exist at runtime.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import type { Bindable, Binding } from '../index.js';
1+
import type { Bindable } from '../index.js';
22

33
/** Anything except a function */
44
export type NotFunction<T> = T extends Function ? never : T;
55

66
export type RemoveBindable<Props extends Record<string, any>> = {
7-
[Key in keyof Props as NonNullable<Props[Key]> extends Binding<unknown>
8-
? never
9-
: Key]: Props[Key] extends Bindable<infer Value> ? Value : Props[Key];
7+
[Key in keyof Props]: Props[Key] extends Bindable<infer Value> ? Value : Props[Key];
108
};

packages/svelte/tests/types/component.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ function binding<T>(value: T): Binding<T> {
191191
class Explicit extends SvelteComponent<{
192192
foo: string;
193193
bar: Bindable<boolean>;
194-
baz?: Binding<string>;
195194
}> {
196195
constructor(options: ComponentConstructorOptions<{ foo: string; bar: Bindable<boolean> }>) {
197196
super(options);
@@ -211,18 +210,10 @@ mount(Explicit, { target: null as any, props: { foo: 'foo', bar: true } });
211210
mount(Explicit, {
212211
target: null as any,
213212
props: {
214-
baz: '',
215213
// @ts-expect-error
216214
bar: binding(true)
217215
}
218216
});
219-
mount(Explicit, {
220-
target: null as any,
221-
props: {
222-
// @ts-expect-error
223-
baz: ''
224-
}
225-
});
226217

227218
class Implicit extends SvelteComponent<{ foo: string; bar: boolean }> {}
228219
new Implicit({ target: null as any, props: { foo: 'foo', bar: true } });

packages/svelte/types/index.d.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ declare module 'svelte' {
2626
[Key in keyof T]: Bindable<T[Key]>;
2727
};
2828

29-
type StripBindable<Props extends Record<string, any>> = {
30-
[Key in keyof Props]: Props[Key] extends Bindable<infer Value> ? Value : Props[Key];
31-
};
32-
3329
/**
3430
* Utility type for ensuring backwards compatibility on a type level:
3531
* - If there's a default slot, add 'children' to the props
@@ -93,7 +89,7 @@ declare module 'svelte' {
9389
* Does not exist at runtime.
9490
* ### DO NOT USE!
9591
* */
96-
$$prop_def: StripBindable<Props>; // Without PropsWithChildren: unnecessary, causes type bugs
92+
$$prop_def: RemoveBindable<Props>; // Without PropsWithChildren: unnecessary, causes type bugs
9793
/**
9894
* For type checking capabilities only.
9995
* Does not exist at runtime.
@@ -247,9 +243,7 @@ declare module 'svelte' {
247243
type NotFunction<T> = T extends Function ? never : T;
248244

249245
type RemoveBindable<Props extends Record<string, any>> = {
250-
[Key in keyof Props as NonNullable<Props[Key]> extends Binding<unknown>
251-
? never
252-
: Key]: Props[Key] extends Bindable<infer Value> ? Value : Props[Key];
246+
[Key in keyof Props]: Props[Key] extends Bindable<infer Value> ? Value : Props[Key];
253247
};
254248
/**
255249
* The `onMount` function schedules a callback to run as soon as the component has been mounted to the DOM.

0 commit comments

Comments
 (0)