This is a typings PR and the companion PR to sveltejs/language-tools#2336
It introduces two new types:
- Binding: Marks a property as being bound (i.e. you must do bind:x)
- Bindable: Marks a property as being able to be bound (i.e. you can do bind:x)
Language tools then uses this generate code accordingly which then generates type errors.
All the other type gymnastics are there to ensure that you don't interact with these bindable types when using mount or hydrate or ComponentProps<MyComponent>, i.e. these two types should be mostly opaque for day-to-day users.
For backwards-compatibility, all properties are automatically wrapped with Bindable, which means existing type definition files will continue to work from a types perspective. Language tools opts into strict bindability by providing its own constructor definition for all generated classes in runes mode which omits the "wrap everything with bindable" behavior.
// Utility type for ensuring backwards compatibility on a type level: If there's a default slot, add 'children' to the props if it doesn't exist there already
typePropsWithChildren<Props,Slots>=Props&
(Propsextends{children?: any}
?{}
:Slotsextends{default:any}
?{children?: Snippet}
/** Tooling for types uses this for properties are being used with `bind:` */
// Utility type for ensuring backwards compatibility on a type level: If there's a default slot, add 'children' to the props if it doesn't exist there already
typePropsWithChildren<Props,Slots>=Props&
(Propsextends{children?: any}
?{}
:Slotsextends{default:any}
?{children?: Snippet}
/** Tooling for types uses this for properties are being used with `bind:` */