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

🐛 Bug: isTypeParameter should not be a type guard #382

Open
3 tasks done
danvk opened this issue Feb 4, 2024 · 2 comments
Open
3 tasks done

🐛 Bug: isTypeParameter should not be a type guard #382

danvk opened this issue Feb 4, 2024 · 2 comments
Labels
status: accepting prs Please, send a pull request to resolve this! 🙏 type: bug Something isn't working :( 🐛

Comments

@danvk
Copy link

danvk commented Feb 4, 2024

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

I'd expect code like this to produce the expected types:

function dealWithType(type: ts.Type) {
  if (tsutils.isTypeParameter(type)) {
    type  // type is ts.TypeParameter
  } else {
    type  // type is ts.Type… or something that includes all types other than type parameters
  }
}

Actual

The TS type of type in the else branch is never. This doesn't match reality at runtime, where the else branch is very much alive.

Additional Info

The issue is that this is how the types are declared in typescript.d.ts:

    interface InstantiableType extends Type {
    }
    interface TypeParameter extends InstantiableType {
    }

i.e. TypeParameter = Type.

So long as that's the case, it would be better if isTypeParameter were not declared as a type guard.

@danvk danvk added the type: bug Something isn't working :( 🐛 label Feb 4, 2024
@JoshuaKGoldberg JoshuaKGoldberg added the status: accepting prs Please, send a pull request to resolve this! 🙏 label Feb 4, 2024
@JoshuaKGoldberg
Copy link
Owner

@all-contributors please add @danvk for bug.

🤖 Beep boop! This comment was added automatically by all-contributors-auto-action.
Not all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed.
...and of course, thank you for contributing! 💙

Copy link
Contributor

@JoshuaKGoldberg

I've put up a pull request to add @danvk! 🎉

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

JoshuaKGoldberg pushed a commit that referenced this issue Feb 5, 2024
Adds @danvk as a contributor for bug.

This was requested by JoshuaKGoldberg [in this
comment](#382 (comment))

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! 🙏 type: bug Something isn't working :( 🐛
Projects
None yet
Development

No branches or pull requests

2 participants