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'.
The "Type 'void' is not assignable to type" TypeScript error occurs when we forget to return a value from a function, so the function gets an implicit return type of void . To solve the error, make sure you return a value of the correct type from your functions before the assignment.
When a function definition has a void return type, it means the function must not return anything. If you need to resolve the Promise with a value of another type, pass the specific type to the generic. Copied! The Promise above can only be resolved with a number.
promise<void> may be used to create future<void> objects which have no value. In addition, a promise<void> can be constructed from a promise<T> where T is any type. This allows a promise<void> to be used by code which only needs to be able to renege on a promise and not fulfill it.
it works by modifying : Promise<void>
into : Promise<any>
,
or to cast new Promise
into new Promise<void>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With