title: TS1108 (TS) A 'return' statement can only be used within a function body - knockout js, durandal, typescript
body: <p>I've been tasked with updating an application that was written in 2015.  It hasn't been touched since then.  I pulled the Solution into VS 2019 and after figuring out a new NuGet errors and modifying the ajax calls I'm left with an error I'm not familiar with.  I can't find anything on Google and I've looked all over this site as well.  I've never used durandal before and have limited knockout experience.  I know this worked and compiled and it runs now on the server but won't compile or run for me now.  If I need to add anything else please let me know.  There are three of these models with the same error.  Thanks all!</p>
  <p>This is saved under a folder named viewmodels as subscriptions.ts.</p>
  <pre><code>/// &lt;reference path=&quot;../../scripts/typings/knockout.validation/knockout.validation.d.ts&quot; /&gt;
  /// &lt;reference path=&quot;../../scripts/typings/bootstrap/bootstrap.d.ts&quot; /&gt;
  
  import system = require(&quot;durandal/system&quot;);
  import settings = require(&quot;settings&quot;);
  import models = require(&quot;models&quot;);
  
  class SubscriptionsViewModel {
      eventNames: KnockoutObservableArray&lt;string&gt;;
      eventName: KnockoutObservable&lt;string&gt;;
      pagination: models.Pagination;
      searchMessage: KnockoutObservable&lt;string&gt;;
      subscriptionCount: KnockoutObservable&lt;number&gt;;
      subscriptions: KnockoutObservableArray&lt;models.Subscription&gt;;
      filteredSubscriptions: KnockoutObservableArray&lt;models.Subscription&gt;;
      selectedSubscription: KnockoutObservable&lt;models.Subscription&gt;;
      subscriptionHeaders: Array&lt;models.GridHeader&gt;;
  
      constructor() {
          this.eventNames = ko.observableArray([]);
          this.eventName = ko.observable(&quot;&quot;);
          this.pagination = new models.Pagination();
          this.searchMessage = ko.observable(&quot;&quot;);
          this.subscriptionCount = ko.observable(0);
          this.subscriptions = ko.observableArray([]);
          this.filteredSubscriptions = ko.observableArray([]);
  
          this.selectedSubscription = ko.observable(new models.Subscription({}));
  
          this.subscriptionHeaders = [
              new models.GridHeader({ title: '', sortPropertyName: '', columnType: 'image' }),
              new models.GridHeader({ title: 'Event Name', sortPropertyName: 'eventName', columnType: 'string' }),
              new models.GridHeader({ title: 'Has XSLT', sortPropertyName: 'hasXSLT', columnType: 'string' })
          ];
  
          this.pagination.itemsPerPage.subscribe((newValue: number): void =&gt; {
              this.searchSubscriptions();
          });
  
          this.pagination.currentPage.subscribe((newValue: number): void =&gt; {
              this.searchSubscriptions();
          });
      }
  
      //#region Search Subscriptions
      searchSubscriptions = (): void =&gt; {
          var countUri = settings.serviceUri + &quot;api/Subscription/Count/&quot;;
          var subscriptionUri = settings.serviceUri + &quot;api/Subscription/?top=&quot; + this.pagination.top() + &quot;&amp;skip=&quot; + this.pagination.skip();
  
          if (this.eventName().length &gt; 0) {
              countUri = settings.serviceUri + &quot;api/Subscription/Count/StartsWith/&quot; + this.eventName();
              subscriptionUri = settings.serviceUri + &quot;api/Subscription/StartsWith/&quot; + this.eventName() + &quot;?top=&quot; + this.pagination.top() + &quot;&amp;skip=&quot; + this.pagination.skip();
          }
  
          $.ajax({
              url: countUri,
              type: &quot;GET&quot;,
              dataType: &quot;json&quot;
          }).then((data: any): JQueryXHR =&gt; {
                  this.subscriptionCount(data);
                  this.pagination.totalItems(data);
  
                  return $.ajax({
                      url: subscriptionUri,
                      type: &quot;GET&quot;,
                      dataType: &quot;json&quot;
                  });
              }).done((data: any): void =&gt; {
                  var subscriptions = new Array&lt;models.Subscription&gt;();
                  for (var i = 0; i &lt; data.length; i++) {
                      subscriptions.push(new models.Subscription(data[i]));
                  }
  
                  this.filteredSubscriptions(subscriptions);
  
                  if (this.filteredSubscriptions().length == 0) {
                      this.searchMessage(&quot;No subscriptions found!&quot;);
                  }
                  else {
                      this.searchMessage(this.filteredSubscriptions().length + &quot; subscriptions (&quot; + this.subscriptionCount() + &quot; total)&quot;);
                      this.pagination.pageMessage(&quot;Page &quot; + this.pagination.currentPage() + &quot; of &quot; + this.pagination.totalPages());
                  }
              });
      }
      //#endregion
  
      //#region Get Subscriptions
      getSubscriptions = (): void =&gt; {
          if (this.eventNames().length == 0) {
              $.ajax({
                  url: settings.serviceUri + 'api/Subscription',
                  //method: 'GET',
                  type: 'GET',
                  dataType: 'json'
              }).done((data: any): void =&gt; {
                      for (var i = 0; i &lt; data.length; i++) {
                          this.eventNames.push(data[i].EventName.trim());
                          this.subscriptions.push(data[i]);
                      }
                  });
          }
      }
      //#endregion
  
      populateSubscriptionDetails = (data: any): void =&gt; {
          this.selectedSubscription(data);
          $('#subscriptionDetailsModal').modal();
      }
  }
  
  var vm: SubscriptionsViewModel = new SubscriptionsViewModel();
  
  return {
      displayName: 'Subscriptions',
      description: 'ENS Subscriptions',
      attached: (): void =&gt; {
          vm.getSubscriptions();
      },
      eventNames: vm.eventNames,
      eventName: vm.eventName,
      pagination: vm.pagination,
      searchSubscriptions: vm.searchSubscriptions,
      searchMessage: vm.searchMessage,
      subscriptions: vm.subscriptions,
      filteredSubscriptions: vm.filteredSubscriptions,
      subscriptionHeaders: vm.subscriptionHeaders,
      populateSubscriptionDetails: vm.populateSubscriptionDetails,
      selectedSubscription: vm.selectedSubscription
  }
  </code></pre>
  <p>This is the error and all it tells me:</p>
  <p>Error: TS1108 (TS) A 'return' statement can only be used within a function body</p>