svelte2tsx 0.7.19 → 0.7.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -2286,7 +2286,6 @@ class InlineComponent {
2286
2286
  this.eventsTransformation = [];
2287
2287
  this.snippetPropsTransformation = [];
2288
2288
  this.endTransformation = [];
2289
- this.originalName = this.node.name;
2290
2289
  if (parent) {
2291
2290
  parent.child = this;
2292
2291
  }
@@ -2828,12 +2827,6 @@ function handleBinding(str, attr, parent, element, preserveBind, isSvelte5Plus)
2828
2827
  if (isSvelte5Plus && element instanceof InlineComponent) {
2829
2828
  // To check if property is actually bindable
2830
2829
  element.appendToStartEnd([`${element.name}.$$bindings = '${attr.name}';`]);
2831
- // To check if the binding is also assigned to the variable (only works when there's no assertion, we can't transform that)
2832
- if (!isTypescriptNode(attr.expression)) {
2833
- element.appendToStartEnd([
2834
- `${expressionStr} = __sveltets_binding_value(${element.originalName}, '${attr.name}');`
2835
- ]);
2836
- }
2837
2830
  }
2838
2831
  if (element instanceof Element) {
2839
2832
  element.addAttribute(name, value);
@@ -3831,6 +3824,9 @@ class ComponentEvents {
3831
3824
  setComponentEventsInterface(node, astOffset) {
3832
3825
  this.componentEventsInterface.setComponentEventsInterface(node, this.str, astOffset);
3833
3826
  }
3827
+ hasEvents() {
3828
+ return this.eventsClass.events.size > 0;
3829
+ }
3834
3830
  hasStrictEvents() {
3835
3831
  return this.componentEventsInterface.isPresent() || this.strictEvents;
3836
3832
  }
@@ -5171,7 +5167,7 @@ class ExportedNames {
5171
5167
  return this.usesAccessors ? names.length > 0 : names.some(([, { isLet }]) => !isLet);
5172
5168
  }
5173
5169
  hasPropsRune() {
5174
- return this.isSvelte5Plus && (this.$props.type || this.$props.comment);
5170
+ return this.isSvelte5Plus && !!(this.$props.type || this.$props.comment);
5175
5171
  }
5176
5172
  checkGlobalsForRunes(globals) {
5177
5173
  const runes = ['$state', '$derived', '$effect']; // no need to check for props, already handled through other means in here
@@ -6456,7 +6452,7 @@ function addComponentExport(params) {
6456
6452
  addSimpleComponentExport(params);
6457
6453
  }
6458
6454
  }
6459
- function addGenericsComponentExport({ strictEvents, canHaveAnyProp, exportedNames, componentDocumentation, fileName, mode, usesAccessors, str, generics, usesSlots, isSvelte5, noSvelteComponentTyped }) {
6455
+ function addGenericsComponentExport({ events, canHaveAnyProp, exportedNames, componentDocumentation, fileName, mode, usesAccessors, str, generics, usesSlots, isSvelte5, noSvelteComponentTyped }) {
6460
6456
  const genericsDef = generics.toDefinitionString();
6461
6457
  const genericsRef = generics.toReferencesString();
6462
6458
  const doc = componentDocumentation.getFormatted();
@@ -6470,7 +6466,7 @@ class __sveltets_Render${genericsDef} {
6470
6466
  return ${props(true, canHaveAnyProp, exportedNames, `render${genericsRef}()`)}.props;
6471
6467
  }
6472
6468
  events() {
6473
- return ${events(strictEvents, `render${genericsRef}()`)}.events;
6469
+ return ${_events(events.hasStrictEvents() || exportedNames.usesRunes(), `render${genericsRef}()`)}.events;
6474
6470
  }
6475
6471
  slots() {
6476
6472
  return render${genericsRef}().slots;
@@ -6490,14 +6486,27 @@ ${isSvelte5
6490
6486
  if (isSvelte5) {
6491
6487
  // Don't add props/events/slots type exports in dts mode for now, maybe someone asks for it to be back,
6492
6488
  // but it's safer to not do it for now to have more flexibility in the future.
6489
+ let eventsSlotsType = [];
6490
+ if (events.hasEvents() || !exportedNames.usesRunes()) {
6491
+ eventsSlotsType.push(`$$events?: ${returnType('events')}`);
6492
+ }
6493
+ if (usesSlots) {
6494
+ eventsSlotsType.push(`$$slots?: ${returnType('slots')}`);
6495
+ eventsSlotsType.push(`children?: any`);
6496
+ }
6493
6497
  const propsType = !canHaveAnyProp && exportedNames.hasNoProps()
6494
- ? `{$$events?: ${returnType('events')}${usesSlots ? `, $$slots?: ${returnType('slots')}, children?: any` : ''}}`
6495
- : `${returnType('props')} & {$$events?: ${returnType('events')}${usesSlots ? `, $$slots?: ${returnType('slots')}, children?: any` : ''}}`;
6498
+ ? `{${eventsSlotsType.join(', ')}}`
6499
+ : `${returnType('props')} & {${eventsSlotsType.join(', ')}}`;
6500
+ const bindingsType = `ReturnType<__sveltets_Render${generics.toReferencesAnyString()}['bindings']>`;
6501
+ // Sadly, due to a combination of requirements and TypeScript limitations, we need to always create both a legacy class component and function component type.
6502
+ // - Constraints: Need to support Svelte 4 class component types, therefore we need to use __sveltets_2_ensureComponent to transform function components to classes
6503
+ // - Limitations: TypeScript is not able to preserve generics during said transformation (i.e. there's no way to express keeping the generic etc)
6504
+ // TODO Svelte 6/7: Switch this around and not use new Component in svelte2tsx anymore, which means we can remove the legacy class component. We need something like _ensureFnComponent then.
6496
6505
  statement +=
6497
6506
  `\ninterface $$IsomorphicComponent {\n` +
6498
6507
  ` new ${genericsDef}(options: import('svelte').ComponentConstructorOptions<${returnType('props') + (usesSlots ? '& {children?: any}' : '')}>): import('svelte').SvelteComponent<${returnType('props')}, ${returnType('events')}, ${returnType('slots')}> & { $$bindings?: ${returnType('bindings')} } & ${returnType('exports')};\n` +
6499
6508
  ` ${genericsDef}(internal: unknown, props: ${propsType}): ${returnType('exports')};\n` +
6500
- ` z_$$bindings?: ReturnType<__sveltets_Render${generics.toReferencesAnyString()}['bindings']>;\n` +
6509
+ ` z_$$bindings?: ${bindingsType};\n` +
6501
6510
  `}\n` +
6502
6511
  `${doc}const ${className || '$$Component'}: $$IsomorphicComponent = null as any;\n` +
6503
6512
  surroundWithIgnoreComments(`type ${className || '$$Component'}${genericsDef} = InstanceType<typeof ${className || '$$Component'}${genericsRef}>;\n`) +
@@ -6523,13 +6532,18 @@ ${isSvelte5
6523
6532
  }
6524
6533
  str.append(statement);
6525
6534
  }
6526
- function addSimpleComponentExport({ strictEvents, isTsFile, canHaveAnyProp, exportedNames, componentDocumentation, fileName, mode, usesAccessors, str, usesSlots, noSvelteComponentTyped, isSvelte5 }) {
6527
- const propDef = props(isTsFile, canHaveAnyProp, exportedNames, events(strictEvents, 'render()'));
6535
+ function addSimpleComponentExport({ events, isTsFile, canHaveAnyProp, exportedNames, componentDocumentation, fileName, mode, usesAccessors, str, usesSlots, noSvelteComponentTyped, isSvelte5 }) {
6536
+ const propDef = props(isTsFile, canHaveAnyProp, exportedNames, _events(events.hasStrictEvents(), 'render()'));
6528
6537
  const doc = componentDocumentation.getFormatted();
6529
6538
  const className = fileName && classNameFromFilename(fileName, mode !== 'dts');
6530
6539
  let statement;
6531
6540
  if (mode === 'dts') {
6532
- if (isSvelte5) {
6541
+ if (isSvelte5 && exportedNames.usesRunes() && !usesSlots && !events.hasEvents()) {
6542
+ statement =
6543
+ `\n${doc}const ${className || '$$Component'} = __sveltets_2_fn_component(render());\n` +
6544
+ `export default ${className || '$$Component'};`;
6545
+ }
6546
+ else if (isSvelte5) {
6533
6547
  // Inline definitions from Svelte shims; else dts files will reference the globals which will be unresolved
6534
6548
  statement =
6535
6549
  `\ninterface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
@@ -6586,10 +6600,17 @@ declare function $$__sveltets_2_isomorphic_component<
6586
6600
  }
6587
6601
  else {
6588
6602
  if (isSvelte5) {
6589
- statement =
6590
- `\n${doc}const ${className || '$$Component'} = __sveltets_2_isomorphic_component${usesSlots ? '_slots' : ''}(${propDef});\n` +
6591
- surroundWithIgnoreComments(`type ${className || '$$Component'} = InstanceType<typeof ${className || '$$Component'}>;\n`) +
6592
- `export default ${className || '$$Component'};`;
6603
+ if (exportedNames.usesRunes() && !usesSlots && !events.hasEvents()) {
6604
+ statement =
6605
+ `\n${doc}const ${className || '$$Component'} = __sveltets_2_fn_component(render());\n` +
6606
+ `export default ${className || '$$Component'};`;
6607
+ }
6608
+ else {
6609
+ statement =
6610
+ `\n${doc}const ${className || '$$Component'} = __sveltets_2_isomorphic_component${usesSlots ? '_slots' : ''}(${propDef});\n` +
6611
+ surroundWithIgnoreComments(`type ${className || '$$Component'} = InstanceType<typeof ${className || '$$Component'}>;\n`) +
6612
+ `export default ${className || '$$Component'};`;
6613
+ }
6593
6614
  }
6594
6615
  else {
6595
6616
  statement =
@@ -6629,7 +6650,7 @@ function addTypeExport(str, className, type) {
6629
6650
  ];
6630
6651
  }
6631
6652
  }
6632
- function events(strictEvents, renderStr) {
6653
+ function _events(strictEvents, renderStr) {
6633
6654
  return strictEvents ? renderStr : `__sveltets_2_with_any_event(${renderStr})`;
6634
6655
  }
6635
6656
  function props(isTsFile, canHaveAnyProp, exportedNames, renderStr) {
@@ -7040,7 +7061,7 @@ function svelte2tsx(svelte, options = { parse: compiler.parse }) {
7040
7061
  addComponentExport({
7041
7062
  str,
7042
7063
  canHaveAnyProp: !exportedNames.uses$$Props && (uses$$props || uses$$restProps),
7043
- strictEvents: events.hasStrictEvents(), // TODO in Svelte 6 we should also apply strictEvents in runes mode
7064
+ events,
7044
7065
  isTsFile: options === null || options === void 0 ? void 0 : options.isTsFile,
7045
7066
  exportedNames,
7046
7067
  usesAccessors,
package/index.mjs CHANGED
@@ -2266,7 +2266,6 @@ class InlineComponent {
2266
2266
  this.eventsTransformation = [];
2267
2267
  this.snippetPropsTransformation = [];
2268
2268
  this.endTransformation = [];
2269
- this.originalName = this.node.name;
2270
2269
  if (parent) {
2271
2270
  parent.child = this;
2272
2271
  }
@@ -2808,12 +2807,6 @@ function handleBinding(str, attr, parent, element, preserveBind, isSvelte5Plus)
2808
2807
  if (isSvelte5Plus && element instanceof InlineComponent) {
2809
2808
  // To check if property is actually bindable
2810
2809
  element.appendToStartEnd([`${element.name}.$$bindings = '${attr.name}';`]);
2811
- // To check if the binding is also assigned to the variable (only works when there's no assertion, we can't transform that)
2812
- if (!isTypescriptNode(attr.expression)) {
2813
- element.appendToStartEnd([
2814
- `${expressionStr} = __sveltets_binding_value(${element.originalName}, '${attr.name}');`
2815
- ]);
2816
- }
2817
2810
  }
2818
2811
  if (element instanceof Element) {
2819
2812
  element.addAttribute(name, value);
@@ -3811,6 +3804,9 @@ class ComponentEvents {
3811
3804
  setComponentEventsInterface(node, astOffset) {
3812
3805
  this.componentEventsInterface.setComponentEventsInterface(node, this.str, astOffset);
3813
3806
  }
3807
+ hasEvents() {
3808
+ return this.eventsClass.events.size > 0;
3809
+ }
3814
3810
  hasStrictEvents() {
3815
3811
  return this.componentEventsInterface.isPresent() || this.strictEvents;
3816
3812
  }
@@ -5151,7 +5147,7 @@ class ExportedNames {
5151
5147
  return this.usesAccessors ? names.length > 0 : names.some(([, { isLet }]) => !isLet);
5152
5148
  }
5153
5149
  hasPropsRune() {
5154
- return this.isSvelte5Plus && (this.$props.type || this.$props.comment);
5150
+ return this.isSvelte5Plus && !!(this.$props.type || this.$props.comment);
5155
5151
  }
5156
5152
  checkGlobalsForRunes(globals) {
5157
5153
  const runes = ['$state', '$derived', '$effect']; // no need to check for props, already handled through other means in here
@@ -6436,7 +6432,7 @@ function addComponentExport(params) {
6436
6432
  addSimpleComponentExport(params);
6437
6433
  }
6438
6434
  }
6439
- function addGenericsComponentExport({ strictEvents, canHaveAnyProp, exportedNames, componentDocumentation, fileName, mode, usesAccessors, str, generics, usesSlots, isSvelte5, noSvelteComponentTyped }) {
6435
+ function addGenericsComponentExport({ events, canHaveAnyProp, exportedNames, componentDocumentation, fileName, mode, usesAccessors, str, generics, usesSlots, isSvelte5, noSvelteComponentTyped }) {
6440
6436
  const genericsDef = generics.toDefinitionString();
6441
6437
  const genericsRef = generics.toReferencesString();
6442
6438
  const doc = componentDocumentation.getFormatted();
@@ -6450,7 +6446,7 @@ class __sveltets_Render${genericsDef} {
6450
6446
  return ${props(true, canHaveAnyProp, exportedNames, `render${genericsRef}()`)}.props;
6451
6447
  }
6452
6448
  events() {
6453
- return ${events(strictEvents, `render${genericsRef}()`)}.events;
6449
+ return ${_events(events.hasStrictEvents() || exportedNames.usesRunes(), `render${genericsRef}()`)}.events;
6454
6450
  }
6455
6451
  slots() {
6456
6452
  return render${genericsRef}().slots;
@@ -6470,14 +6466,27 @@ ${isSvelte5
6470
6466
  if (isSvelte5) {
6471
6467
  // Don't add props/events/slots type exports in dts mode for now, maybe someone asks for it to be back,
6472
6468
  // but it's safer to not do it for now to have more flexibility in the future.
6469
+ let eventsSlotsType = [];
6470
+ if (events.hasEvents() || !exportedNames.usesRunes()) {
6471
+ eventsSlotsType.push(`$$events?: ${returnType('events')}`);
6472
+ }
6473
+ if (usesSlots) {
6474
+ eventsSlotsType.push(`$$slots?: ${returnType('slots')}`);
6475
+ eventsSlotsType.push(`children?: any`);
6476
+ }
6473
6477
  const propsType = !canHaveAnyProp && exportedNames.hasNoProps()
6474
- ? `{$$events?: ${returnType('events')}${usesSlots ? `, $$slots?: ${returnType('slots')}, children?: any` : ''}}`
6475
- : `${returnType('props')} & {$$events?: ${returnType('events')}${usesSlots ? `, $$slots?: ${returnType('slots')}, children?: any` : ''}}`;
6478
+ ? `{${eventsSlotsType.join(', ')}}`
6479
+ : `${returnType('props')} & {${eventsSlotsType.join(', ')}}`;
6480
+ const bindingsType = `ReturnType<__sveltets_Render${generics.toReferencesAnyString()}['bindings']>`;
6481
+ // Sadly, due to a combination of requirements and TypeScript limitations, we need to always create both a legacy class component and function component type.
6482
+ // - Constraints: Need to support Svelte 4 class component types, therefore we need to use __sveltets_2_ensureComponent to transform function components to classes
6483
+ // - Limitations: TypeScript is not able to preserve generics during said transformation (i.e. there's no way to express keeping the generic etc)
6484
+ // TODO Svelte 6/7: Switch this around and not use new Component in svelte2tsx anymore, which means we can remove the legacy class component. We need something like _ensureFnComponent then.
6476
6485
  statement +=
6477
6486
  `\ninterface $$IsomorphicComponent {\n` +
6478
6487
  ` new ${genericsDef}(options: import('svelte').ComponentConstructorOptions<${returnType('props') + (usesSlots ? '& {children?: any}' : '')}>): import('svelte').SvelteComponent<${returnType('props')}, ${returnType('events')}, ${returnType('slots')}> & { $$bindings?: ${returnType('bindings')} } & ${returnType('exports')};\n` +
6479
6488
  ` ${genericsDef}(internal: unknown, props: ${propsType}): ${returnType('exports')};\n` +
6480
- ` z_$$bindings?: ReturnType<__sveltets_Render${generics.toReferencesAnyString()}['bindings']>;\n` +
6489
+ ` z_$$bindings?: ${bindingsType};\n` +
6481
6490
  `}\n` +
6482
6491
  `${doc}const ${className || '$$Component'}: $$IsomorphicComponent = null as any;\n` +
6483
6492
  surroundWithIgnoreComments(`type ${className || '$$Component'}${genericsDef} = InstanceType<typeof ${className || '$$Component'}${genericsRef}>;\n`) +
@@ -6503,13 +6512,18 @@ ${isSvelte5
6503
6512
  }
6504
6513
  str.append(statement);
6505
6514
  }
6506
- function addSimpleComponentExport({ strictEvents, isTsFile, canHaveAnyProp, exportedNames, componentDocumentation, fileName, mode, usesAccessors, str, usesSlots, noSvelteComponentTyped, isSvelte5 }) {
6507
- const propDef = props(isTsFile, canHaveAnyProp, exportedNames, events(strictEvents, 'render()'));
6515
+ function addSimpleComponentExport({ events, isTsFile, canHaveAnyProp, exportedNames, componentDocumentation, fileName, mode, usesAccessors, str, usesSlots, noSvelteComponentTyped, isSvelte5 }) {
6516
+ const propDef = props(isTsFile, canHaveAnyProp, exportedNames, _events(events.hasStrictEvents(), 'render()'));
6508
6517
  const doc = componentDocumentation.getFormatted();
6509
6518
  const className = fileName && classNameFromFilename(fileName, mode !== 'dts');
6510
6519
  let statement;
6511
6520
  if (mode === 'dts') {
6512
- if (isSvelte5) {
6521
+ if (isSvelte5 && exportedNames.usesRunes() && !usesSlots && !events.hasEvents()) {
6522
+ statement =
6523
+ `\n${doc}const ${className || '$$Component'} = __sveltets_2_fn_component(render());\n` +
6524
+ `export default ${className || '$$Component'};`;
6525
+ }
6526
+ else if (isSvelte5) {
6513
6527
  // Inline definitions from Svelte shims; else dts files will reference the globals which will be unresolved
6514
6528
  statement =
6515
6529
  `\ninterface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
@@ -6566,10 +6580,17 @@ declare function $$__sveltets_2_isomorphic_component<
6566
6580
  }
6567
6581
  else {
6568
6582
  if (isSvelte5) {
6569
- statement =
6570
- `\n${doc}const ${className || '$$Component'} = __sveltets_2_isomorphic_component${usesSlots ? '_slots' : ''}(${propDef});\n` +
6571
- surroundWithIgnoreComments(`type ${className || '$$Component'} = InstanceType<typeof ${className || '$$Component'}>;\n`) +
6572
- `export default ${className || '$$Component'};`;
6583
+ if (exportedNames.usesRunes() && !usesSlots && !events.hasEvents()) {
6584
+ statement =
6585
+ `\n${doc}const ${className || '$$Component'} = __sveltets_2_fn_component(render());\n` +
6586
+ `export default ${className || '$$Component'};`;
6587
+ }
6588
+ else {
6589
+ statement =
6590
+ `\n${doc}const ${className || '$$Component'} = __sveltets_2_isomorphic_component${usesSlots ? '_slots' : ''}(${propDef});\n` +
6591
+ surroundWithIgnoreComments(`type ${className || '$$Component'} = InstanceType<typeof ${className || '$$Component'}>;\n`) +
6592
+ `export default ${className || '$$Component'};`;
6593
+ }
6573
6594
  }
6574
6595
  else {
6575
6596
  statement =
@@ -6609,7 +6630,7 @@ function addTypeExport(str, className, type) {
6609
6630
  ];
6610
6631
  }
6611
6632
  }
6612
- function events(strictEvents, renderStr) {
6633
+ function _events(strictEvents, renderStr) {
6613
6634
  return strictEvents ? renderStr : `__sveltets_2_with_any_event(${renderStr})`;
6614
6635
  }
6615
6636
  function props(isTsFile, canHaveAnyProp, exportedNames, renderStr) {
@@ -7020,7 +7041,7 @@ function svelte2tsx(svelte, options = { parse }) {
7020
7041
  addComponentExport({
7021
7042
  str,
7022
7043
  canHaveAnyProp: !exportedNames.uses$$Props && (uses$$props || uses$$restProps),
7023
- strictEvents: events.hasStrictEvents(), // TODO in Svelte 6 we should also apply strictEvents in runes mode
7044
+ events,
7024
7045
  isTsFile: options === null || options === void 0 ? void 0 : options.isTsFile,
7025
7046
  exportedNames,
7026
7047
  usesAccessors,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte2tsx",
3
- "version": "0.7.19",
3
+ "version": "0.7.21",
4
4
  "description": "Convert Svelte components to TSX for type checking",
5
5
  "author": "David Pershouse",
6
6
  "license": "MIT",
package/svelte-jsx.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  /// <reference lib="dom" />
2
+ // @ts-nocheck
3
+ // nocheck because we don't want to adjust this anymore (only used for Svelte 3)
2
4
 
3
5
  declare namespace svelteHTML {
4
6
 
@@ -207,7 +207,7 @@ declare type ATypedSvelteComponent = {
207
207
  */
208
208
  $$slot_def: any;
209
209
 
210
- $on(event: string, handler: ((e: any) => any) | null | undefined): () => void;
210
+ $on(event: string, handler: any): () => void;
211
211
  }
212
212
  /**
213
213
  * Ambient type only used for intellisense, DO NOT USE IN YOUR PROJECT.
@@ -220,11 +220,36 @@ declare type ATypedSvelteComponent = {
220
220
  * ```
221
221
  */
222
222
  declare type ConstructorOfATypedSvelteComponent = new (args: {target: any, props?: any}) => ATypedSvelteComponent
223
+ // Usage note: Cannot properly transform generic function components to class components due to TypeScript limitations
223
224
  declare function __sveltets_2_ensureComponent<
224
- // @ts-ignore svelte.Component doesn't exist in Svelte 4
225
- T extends ConstructorOfATypedSvelteComponent | (typeof import('svelte') extends { mount: any } ? import('svelte').Component<any, any, any> : never) | null | undefined
226
- // @ts-ignore svelte.Component doesn't exist in Svelte 4
227
- >(type: T): NonNullable<T extends ConstructorOfATypedSvelteComponent ? T : typeof import('svelte') extends { mount: any } ? T extends import('svelte').Component<infer Props extends Record<string, any>> ? typeof import('svelte').SvelteComponent<Props, Props['$$events'], Props['$$slots']> : T : T>;
225
+ T extends
226
+ | ConstructorOfATypedSvelteComponent
227
+ | (typeof import('svelte') extends { mount: any }
228
+ ? // @ts-ignore svelte.Component doesn't exist in Svelte 4
229
+ import('svelte').Component<any, any, any>
230
+ : never)
231
+ | null
232
+ | undefined
233
+ >(
234
+ type: T
235
+ ): NonNullable<
236
+ T extends ConstructorOfATypedSvelteComponent
237
+ ? T
238
+ : typeof import('svelte') extends { mount: any }
239
+ ? // @ts-ignore svelte.Component doesn't exist in Svelte 4
240
+ T extends import('svelte').Component<
241
+ infer Props extends Record<string, any>,
242
+ infer Exports extends Record<string, any>,
243
+ infer Bindings extends string
244
+ >
245
+ ? new (
246
+ options: import('svelte').ComponentConstructorOptions<Props>
247
+ ) => import('svelte').SvelteComponent<Props, Props['$$events'], Props['$$slots']> &
248
+ Exports & { $$bindings: Bindings }
249
+ : never
250
+ : never
251
+ >;
252
+
228
253
  declare function __sveltets_2_ensureArray<T extends ArrayLike<unknown> | Iterable<unknown>>(array: T): T extends ArrayLike<infer U> ? U[] : T extends Iterable<infer U> ? Iterable<U> : any[];
229
254
 
230
255
  type __sveltets_2_PropsWithChildren<Props, Slots> = Props &
@@ -240,6 +265,11 @@ declare function __sveltets_2_runes_constructor<Props extends {}>(render: {props
240
265
 
241
266
  declare function __sveltets_$$bindings<Bindings extends string[]>(...bindings: Bindings): Bindings[number];
242
267
 
268
+ declare function __sveltets_2_fn_component<
269
+ Props extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
270
+ // @ts-ignore Svelte 5 only
271
+ >(klass: {props: Props, exports?: Exports, bindings?: Bindings }): import('svelte').Component<Props, Exports, Bindings>;
272
+
243
273
  interface __sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
244
274
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & { $$bindings?: Bindings } & Exports;
245
275
  (internal: unknown, props: Props extends Record<string, never> ? {$$events?: Events, $$slots?: Slots} : Props & {$$events?: Events, $$slots?: Slots}): Exports & { $set?: any, $on?: any };
@@ -253,16 +283,3 @@ declare function __sveltets_2_isomorphic_component<
253
283
  declare function __sveltets_2_isomorphic_component_slots<
254
284
  Props extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>, Exports extends Record<string, any>, Bindings extends string
255
285
  >(klass: {props: Props, events: Events, slots: Slots, exports?: Exports, bindings?: Bindings }): __sveltets_2_IsomorphicComponent<__sveltets_2_PropsWithChildren<Props, Slots>, Events, Slots, Exports, Bindings>;
256
-
257
- type __sveltets_NonUndefined<T> = T extends undefined ? never : T;
258
-
259
- declare function __sveltets_binding_value<
260
- // @ts-ignore this is only used for Svelte 5, which knows about the Component type
261
- Comp extends typeof import('svelte').Component<any>,
262
- Key extends string
263
- >(comp: Comp, key: Key): Key extends keyof import('svelte').ComponentProps<Comp> ?
264
- // bail on unknown because it hints at a generic type which we can't properly resolve here
265
- // remove undefined because optional properties have it, and would result in false positives
266
- unknown extends import('svelte').ComponentProps<Comp>[Key] ? any : __sveltets_NonUndefined<import('svelte').ComponentProps<Comp>[Key]> : any;
267
- // Overload to ensure typings that only use old SvelteComponent class or something invalid are gracefully handled
268
- declare function __sveltets_binding_value(comp: any, key: string): any
package/svelte-shims.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // @ts-nocheck
2
+ // nocheck because we don't want to adjust this anymore (only used for Svelte 3)
1
3
  // Whenever a ambient declaration changes, its number should be increased
2
4
  // This way, we avoid the situation where multiple ambient versions of svelte2tsx
3
5
  // are loaded and their declarations conflict each other