Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Type Intelligence for `in` operator #31356

Closed
JounQin opened this issue May 12, 2019 · 2 comments
Closed

Incorrect Type Intelligence for `in` operator #31356

JounQin opened this issue May 12, 2019 · 2 comments
Labels

Comments

@JounQin
Copy link

@JounQin JounQin commented May 12, 2019

TypeScript Version: 3.5.0-dev.20190512

Search Terms: Incorrect Type Intelligence

Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

function isPromise(obj: {}) {
  return 'then' in obj && typeof obj.then === 'function'
}

Expected behavior:
No Error

Actual behavior:
Property 'then' does not exist on type 'never'.

Playground Link:
https://www.typescriptlang.org/play/index.html#src=function%20isPromise(obj%3A%20%7B%7D)%20%7B%0D%0A%20%20return%20'then'%20in%20obj%20%26%26%20typeof%20obj.then%20%3D%3D%3D%20'function'%0D%0A%7D

Related Issues:

@JounQin JounQin changed the title Incorrect Type Intelligence Incorrect Type Intelligence for `in` operator May 12, 2019
@jcalz

This comment has been minimized.

Copy link
Contributor

@jcalz jcalz commented May 12, 2019

Duplicate of #21732

@typescript-bot

This comment has been minimized.

Copy link
Collaborator

@typescript-bot typescript-bot commented May 15, 2019

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.