question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changed behaviour in TS2.1 for Promise<void>

See original GitHub issue

In 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:open
  • Created 7 years ago
  • Reactions:10
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
advorkovyycommented, Mar 27, 2017
let x: Promise<void> = Promise.resolve(1) 

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found