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:

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'.

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 badges
Add a comment  | 

1 Answer 1

Reset to default 27

it 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