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

TypeScript definitions for babel-types is* checks should accept any type, not just object #9538

Closed
ian-craig opened this issue Feb 18, 2019 · 1 comment · Fixed by #9539
Closed
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@ian-craig
Copy link
Contributor

Bug Report

Current Behavior
Let's use t.isIdentifier as an example.

Current definition generated in packages\babel-types\lib\index.d.ts:

export function isIdentifier(node: object, opts?: object | null): node is Identifier;

Input Code

const func = t.functionDeclaration(...);

if (t.isIdentifier(func.id, { name: 'foo' })) {
  // Do something
}

Expected behavior/code
This code runs perfectly fine, and if func.id === 'foo' the // Do something will be called.

However, in TypeScript with strictNullChecks you get a type error on compile because func.id has type Identifier | null | undefined, and the argument type is object which does not accept null | undefined.

In actual fact, all the is* validate the value passed to it properly, so there is no need to restrict the type.

Babel Configuration (.babelrc, package.json, cli command)
N/A

Environment

  • Babel version(s): v7.1.3
  • Node/npm version: v10.15.1
  • OS: Windows 10
  • Monorepo: no
  • How you are using Babel: importing - like a plugin would

Possible Solution
Change from object to any type for value of all is* type declarations

I'm happy to submit a PR, should be a very small isolated fix.

@babel-bot
Copy link
Collaborator

Hey @ian-craig! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 24, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants