Skip to content

Commit 1f58030

Browse files
committed
fix
1 parent f61c7c3 commit 1f58030

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

packages/svelte/src/internal/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Bindable, Binding } from '../index.js';
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 Props[Key] extends Binding<unknown>
7+
[Key in keyof Props as NonNullable<Props[Key]> extends Binding<unknown>
88
? never
99
: Key]: Props[Key] extends Bindable<infer Value> ? Value : Props[Key];
1010
};

packages/svelte/tests/types/component.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
mount,
88
hydrate,
99
type Bindable,
10-
type Binding
10+
type Binding,
11+
type ComponentConstructorOptions
1112
} from 'svelte';
1213

1314
SvelteComponent.element === HTMLElement;
@@ -180,14 +181,22 @@ const x: typeof asLegacyComponent = createClassComponent({
180181
// --------------------------------------------------------------------------- bindable
181182

182183
// Test that
183-
// - everything's bindable unless _explicit_ is set to true (for backwards compatibility)
184+
// - everything's bindable unless the component constructor is specifically set telling otherwise (for backwards compatibility)
184185
// - when using mount etc the props are never bindable because this is language-tools only concept
185186

186187
function binding<T>(value: T): Binding<T> {
187188
return value as any;
188189
}
189190

190-
class Explicit extends SvelteComponent<{ foo: string; bar: Bindable<boolean> } & '_explicit_'> {}
191+
class Explicit extends SvelteComponent<{
192+
foo: string;
193+
bar: Bindable<boolean>;
194+
baz?: Binding<string>;
195+
}> {
196+
constructor(options: ComponentConstructorOptions<{ foo: string; bar: Bindable<boolean> }>) {
197+
super(options);
198+
}
199+
}
191200
new Explicit({ target: null as any, props: { foo: 'foo', bar: binding(true) } });
192201
new Explicit({ target: null as any, props: { foo: 'foo', bar: true } });
193202
new Explicit({
@@ -202,11 +211,18 @@ mount(Explicit, { target: null as any, props: { foo: 'foo', bar: true } });
202211
mount(Explicit, {
203212
target: null as any,
204213
props: {
205-
foo: 'foo',
214+
baz: '',
206215
// @ts-expect-error
207216
bar: binding(true)
208217
}
209218
});
219+
mount(Explicit, {
220+
target: null as any,
221+
props: {
222+
// @ts-expect-error
223+
baz: ''
224+
}
225+
});
210226

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

packages/svelte/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ declare module 'svelte' {
247247
type NotFunction<T> = T extends Function ? never : T;
248248

249249
type RemoveBindable<Props extends Record<string, any>> = {
250-
[Key in keyof Props as Props[Key] extends Binding<unknown>
250+
[Key in keyof Props as NonNullable<Props[Key]> extends Binding<unknown>
251251
? never
252252
: Key]: Props[Key] extends Bindable<infer Value> ? Value : Props[Key];
253253
};

0 commit comments

Comments
 (0)