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

ts80007 is incorrect at times? #58126

Closed
6 tasks done
ORESoftware opened this issue Apr 9, 2024 · 3 comments
Closed
6 tasks done

ts80007 is incorrect at times? #58126

ORESoftware opened this issue Apr 9, 2024 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@ORESoftware
Copy link

ORESoftware commented Apr 9, 2024

πŸ” Search Terms

async/await conditional is-promise promise

βœ… Viability Checklist

⭐ Suggestion

For reference, isPromise(x) looks like:

(client as any).ensure = () => {
  if (client.isOpen) {
    return;
  }
  return client.connect();
}

const isPromise = (x: any) => {
  return x && typeof x.then === 'function' && typeof x.catch === 'function';
}

here is what I saw:

image

this is pretty handy code, IMO, more performant etc, big win, but at the same time we all like to avoid if/else where possible, in this case, I think TS shouldn't complain?

πŸ“ƒ Motivating Example

see above

πŸ’» Use Cases

  1. What do you want to use this for? async/await optimizations
  2. What shortcomings exist with current approaches?
  3. What workarounds are you using in the meantime?
@fatcerberus
Copy link

This one isn't a compile error though, is it? I thought it was just a lightbulb in the IDE and you're free to ignore it.

@andrewbranch andrewbranch added the Working as Intended The behavior described is the intended behavior; this is not a bug label Apr 9, 2024
@andrewbranch
Copy link
Member

Just write the return type of isPromise as x is Promise<any> if you want to make the types accurate enough for this suggestion diagnostic to follow

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants