admin管理员组文章数量:1187302
I have the following function :
let templateLoader = (onDidFinishLoad : Function, onDidFailLoad : Function) =>
(url : string) : Promise<void> =>
new Promise(
(resolve,reject) => {
mainWindow.loadURL(url);
mainWindow.webContents.once(
'did-finish-load',
() => {
onDidFinishLoad(resolve);
}
);
mainWindow.webContents.once(
'did-fail-load',
(event,errorCode,errorDescription) => {
onDidFailLoad(reject,errorDescription);
}
);
}
);
I've got the following compilation error:
ERROR in [at-loader] ./app/loaders.ts:9:9 TS2322: Type 'Promise {}' is not assignable to type Promise void. Type '{}' is not assignable to type 'void'.
I have the following function :
let templateLoader = (onDidFinishLoad : Function, onDidFailLoad : Function) =>
(url : string) : Promise<void> =>
new Promise(
(resolve,reject) => {
mainWindow.loadURL(url);
mainWindow.webContents.once(
'did-finish-load',
() => {
onDidFinishLoad(resolve);
}
);
mainWindow.webContents.once(
'did-fail-load',
(event,errorCode,errorDescription) => {
onDidFailLoad(reject,errorDescription);
}
);
}
);
I've got the following compilation error:
Share Improve this question edited Sep 26, 2017 at 2:44 Val 22.8k11 gold badges71 silver badges87 bronze badges asked Jul 28, 2017 at 10:51 Anatoly StrashkevichAnatoly Strashkevich 1,9144 gold badges18 silver badges34 bronze badgesERROR in [at-loader] ./app/loaders.ts:9:9 TS2322: Type 'Promise {}' is not assignable to type Promise void. Type '{}' is not assignable to type 'void'.
1 Answer
Reset to default 27it works by modifying : Promise<void>
into : Promise<any>
,
or to cast new Promise
into new Promise<void>
.
本文标签: javascriptTypescriptType 39Promiseltgt39 is not assignable to type 39Promiseltvoidgt39Stack Overflow
版权声明:本文标题:javascript - Typescript : Type 'Promise<{}>' is not assignable to type 'Promise<voi 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738344902a2077879.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论