Update1:我根据Pankaj回答更新了代码
嘿,我在代码库中更新了你的代码...但是我仍然收到这样的错误...任何想法......在分号结束时[ ts]预期属性分配。
Observable.fromEvent( $("#AnimalRatsGrid .RatNameFile"), "click")
.do((e) => {
console.log("I am here");
alert("I am here");
kendo.ui.progress($("#loading"), true);
}).map(e => "Rats/color/black?RatId="+"7887878787")
.mergeMap(vals => that.nbcuService.getResponse(vals, 'get', ""))
//.map(data => { blob: new Blob([data], { type: 'application/octet-stream' }), fire: "untitled1.txt" })
.map(data => {
//creating customData object
let customData: any = {
blob: new Blob([data],
{
type: 'application/octet-stream'
}),
fire: "untitled1.txt" //
};
return customData; //returning it from map.
})
.subscribe(
({blob, fire}) => that.nbcuService.saveAs(blob,fire),
err => { }
);
});
但我的视觉工作室出现了三个错误。
// [ts]未使用的标签。 // [ts]找不到名字'fire'.any // [ts]类型'void'没有属性'blob'且没有字符串索引签名。
你能告诉我如何解决..
Observable.fromEvent($("#AnimalRatsGrid .RatNameFile"), "click")
.do((e) => {
console.log("I am here");
alert("I am here");
kendo.ui.progress($("#loading"), true);
}).map(e => "Rats/color/black?RatId=" + "7887878787")
.mergeMap(vals => that.sportsservice.getResponse(vals, 'get', ""))
.map(data => {
blob: new Blob([data], // [ts] Unused label.
{
type: 'application/octet-stream'
}),
fire: "untitled1.txt" // [ts] Cannot find name 'fire'.any
})
.subscribe(
//[ts] Type 'void' has no property 'blob' and no string index signature.
({
blob,
fire
}) => that.sportsservice.saveAs(blob, fire),
err => {}
);
});
答案 0 :(得分:0)
Typescript正在大喊大叫,因为可观察的最后一部分,map
函数不会返回任何void
的对象。当你有lambda表达式像.map(item => item.someProp)
时,lambda会隐式返回RHS,当你在lambda函数中使用{ }
(括号)时,你必须明确地从function
返回所需的结果。
.map(data => {
//creating customData object
let customData: any = {
blob: new Blob([data],
{
type: 'application/octet-stream'
}),
fire: "untitled1.txt" //
};
return customData; //returning it from map.
})