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

🐛 useImportType false positive when identifier shares a name with a TypeScript type #4640

Open
1 task done
ahrjarrett opened this issue Nov 26, 2024 · 1 comment
Open
1 task done
Labels
S-Needs triage Status: this issue needs to be triaged

Comments

@ahrjarrett
Copy link

ahrjarrett commented Nov 26, 2024

Environment information

CLI:
  Version:                      1.9.4
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.11.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/9.7.1"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    true
  VCS disabled:                 false

Workspace:
  Open Documents:               0

What happened?

This one's easy to reproduce.

With useImportType* enabled, biome treats certain term-level identifiers (such as object) as types, even if the identifier is used as a value in that file.

Since the unsafe flag is opt-in, this has the potential to cause a runtime exception unless it's caught during review / by our CI/CD pipeline.

Config:

I believe useImportType is turned on by default, so any configuration that doesn't override it is enough to reproduce.

Repro:

/// ex-01.ts
export namespace object {
  export const keys = globalThis.Object.keys
}

This is what I wrote:

/// ex-02.ts
import { object } from "./ex_01.js"

console.log(object.keys(globalThis))

This is what biome changes it to:

/// ex-02.ts

//       vvvv
import { type object } from "./ex_01.js"

//            vv this now throws
console.log(object.keys(globalThis))

Expected result

It shouldn't add inline type keywords if the identifier is used as a term in that same file.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ahrjarrett ahrjarrett added the S-Needs triage Status: this issue needs to be triaged label Nov 26, 2024
@ematipico
Copy link
Member

I can't reproduce it in the playground, this means it's been fixed. Can you try to latest nightly to confirm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-Needs triage Status: this issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants