title: Chaining Promises correctly
body: <p>I want to create a list if it doesn't exist and then create the fields, aka ensure.  I'm having trouble understanding how to set the promises:</p>
  
  <pre><code>public getLocations(): Promise&lt;ILocations[]&gt; {
      let promise: Promise&lt;ILocations[]&gt; = new Promise&lt;ILocations[]&gt;((resolve, reject): void =&gt; {
          sp.web.lists.ensure("DeliveryBoardLocations")
              .then((ler: ListEnsureResult): Promise&lt;ListEnsureResult&gt; =&gt; {
                  console.log("got list ensure result");
  
                  if (ler.created) {
                      console.log("Locations was created");
  
                      let batch = sp.web.createBatch();
  
                      ler.list.fields.inBatch(batch).addText("textField");
                      ler.list.fields.inBatch(batch).addDateTime("dateField");
                      ler.list.fields.inBatch(batch).addBoolean("booleanField");
  
                      batch.execute()
                          .then((): Promise&lt;ListEnsureResult&gt; =&gt; {
                              console.log("fields created");
  
                              let batch = sp.web.createBatch();
                              let view = ler.list.defaultView;
  
                              view.fields.inBatch(batch).add("textField");
                              view.fields.inBatch(batch).add("dateField");
                              view.fields.inBatch(batch).add("booleanField");
  
                              batch.execute()
                                  .then((): Promise&lt;ListEnsureResult&gt; =&gt; {
                                      console.log("fields added to view; returning ler");
  
                                      return ler;
                                  });
                          });
  
                      // return;
                  }
                  else {
                      console.log("Locations already existed; returning ler");
  
                      resolve(ler.list);
                      return Promise.reject("List Exists");
                  }
  
                  console.log("after if stmt");
              })
              .then((ler): void =&gt; {
                  console.log("ler: ", ler);
                  console.log("ler.list: ", ler.list);
                  console.log("ler.list.items: ", ler.list.items);
  
                  resolve(ler.list.items.getAll());
              });
      });
  
      return promise;
  }
  </code></pre>
  
  <p>Console shows:</p>
  
  <pre><code>LocationsService.ts:16 got list ensure result
  LocationsService.ts:19 Locations was created
  LocationsService.ts:56 after if stmt
  LocationsService.ts:59 ler:  undefined
  LocationsService.ts:31 fields created
  LocationsService.ts:43 fields added to view; returning ler
  </code></pre>
  
  <p>I want to call ensure; if result comes back that the list was created then create the columns and display them.  Then return the list so I can get all the items and return the items.  If the list is created, return the items.</p>
  
  <p>I'm having trouble figuring out how this should be handled.</p>