2016-08-22 6 views
0
에서 관찰을 만드는

내가 센드 메일에서 관찰을 만들려고하고, 현재 해당 내 시험은 다음과 같습니다transporter.sendMail

[TypeError: Cannot convert undefined or null to object]

:

/// <reference path="../../typings/index.d.ts" /> 
import * as chai from "chai"; 
let assert = chai.assert; 
const Rx = require('rxjs'); 
var nodemailer = require('nodemailer'); 

describe("emailPlugin", function() { 
    it.only('should emit one value from a callback', function() { 
     let mailOptions = { 
      from: '"Fred Foo " <[email protected]>', // sender address 
      to: '[email protected]', // list of receivers; comma seperated 
      subject: 'Hello ✔', // Subject line 
      text: 'Hello world ', // plaintext body 
      html: '<b>Hello world </b>' // html body 
     }; 
     let transporter = nodemailer.createTransport('smtps://MY%40gmail.com:[email protected]'); 

     let boundCallback = Rx.Observable.bindNodeCallback(transporter.sendMail); 
     boundCallback(mailOptions, function(error, info){ 
      if(error){ 
       return error; 
      } 
      return info.response; 
     }).subscribe(x => console.log(x), e => console.error(e)); 
    }); 
}); 

결과는 오류입니다

누군가 나를 도와 줄 수 있습니까?

답변

0

나는 당신과 똑같은 문제가 있었지만,이 문제를 해결했다. 대신에 :

let boundCallback = Rx.Observable.bindNodeCallback(transporter.sendMail); 

이 나를 위해 작동합니다

let boundCallback = Rx.Observable.bindNodeCallback((options: any, callback: any) => { 
    return transporter.sendMail(options, callback); 
}); 

나는 그것이 나에게 원래의 형태가 정확해야한다 보인다 왜 아무 생각이 없습니다. TypeScript가 sendMail 함수 유형으로 고생하는 것처럼 보입니다. 희망이 도움이됩니다!