Changed behaviour in TS2.1 for Promise<void>
See original GitHub issueIn typescript 2.0 any promise could be used a promise of type void, this does not seem to be the case in typescript 2.1.
I couldn’t find this listed as a breaking change or any existing tickets so raised this one.
TypeScript Version: 2.1.4
Code
function testVoidPromises(promiseA: Promise<void>, promiseB: Promise<void>): Promise<void> {
return Promise.all([promiseA, promiseB]);
}
Expected behavior: This compiles without errors in typescript 2.0
Actual behavior: This fails to compile in typescript 2.1.4 with the following error: test.ts(2,9): error TS2322: Type ‘Promise<[void, void]>’ is not assignable to type ‘Promise<void>’. Type ‘[void, void]’ is not assignable to type ‘void’.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:10
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Typescript async function return type void vs Promise<void>
Declaring the function itself has the behavior you expected. const asyncFunc: () => void = async () => { await new Promise(resolve ...
Read more >ts-promise | Yarn - Package Manager
TS-Promise is a fast, robust, type-safe promise library. Features: Promises/A+ 1.1 compliant; ES6 Promise interface compatible; Possibly-unhandled rejection ...
Read more >async function returning Promise<void> successfully ... - Reddit
In short, I'm trying to understand why public async func(): Promise<void> {} is a valid implementation of an interface method declared as ...
Read more >TS – Tectonics & Structural Geology - EGU21 - EGUsphere
TS2.1 – Deformation mechanisms and microstructures. EGU21-1905 | vPICO presentations | TS2.1. Microstructures reveal brittle and viscous flow during exhumation ...
Read more >Operating Guide for Merchant Card Processing v8.0417 | TSYS
If Bank allows Merchant to conduct preauthorized Debit Card Transactions, ... (f) Merchant may void a Transaction electronically, but only if the voiding ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, almost four years later I still run into this issue continuously: https://www.typescriptlang.org/play/?ssl=18&ssc=26&pln=1&pc=1#code/JYOwLgpgTgZghgYwgAgEoQM4AdkG8BQyRyCA9gCYQBcyIArgLYBG0A3IcUxQJ40ZhRQAc3YBffPhh0QCMMFIhkYOAGsIAMRAAKGCBpaAlMgC8APmQA3UsHJGCxZFAhg6UEGIlSZchUtUQABShSBmAMDW1dfSMzZCCQsIgAHisbUzsOIicXNw98MhB+ZF0TZEMadGwTcy1cMkoaACYABmaAGmQucl5kACIAeQBpXtEDdgKirGDQ8M1S8rjpxKTKrHNY+JmIADonDFIAGwsIWpIKamQW9s6eGgHh5FH2fGU1TR0QMZf-TcT3qYSs0+rCAA
Afaik,
() => T
assigns to() => void
just fine, but() => Promise<T>
does not assign to() => Promise<void>
. What’s the correct pattern/workaround here?gives TS2322:Type ‘Promise<number>’ is not assignable to type ‘Promise<void>’. Type ‘number’ is not assignable to type ‘void’.
So, this is obviously a bug in typescript compiler