Skip to content

Promise.then with Any Return Type Produces Incorrect error #12725

Closed
@mjbvz

Description

From: microsoft/vscode#16819

TypeScript Version: 2.1.4-insiders.20161206

Code

interface CompletionItem {
	a(): number;
}

function func(item: CompletionItem): Promise<CompletionItem> {
	const temp: Promise<any> = null
	return Promise.resolve('abc').then(service => {
		return temp;
	});
}

Expected behavior:
No errors.

Actual behavior:
Error:

Type 'Promise<string>' is not assignable to type 'Promise<CompletionItem>'.
  Type 'string' is not assignable to type 'CompletionItem'.

I believe the error comes from then selecting the incorrect overload during compilation. Changing the type to Promise.resolve(3) changes the error message to Type Promise<number> is not...

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions