Repository navigation
Conversation
A type-only binding is erased at compile time, so the identifier does not exist as a value at runtime. Reporting the string title and autofixing it to the identifier produced code that does not compile. Fixes vitest-dev#954
|
Does this also handle the namespace import ( |
|
Yes —
Added two valid cases in 51155c4 to lock it in: import type * as myFunction from "./myFunction"
describe("myFunction", () => {}) // string-title path
import type * as myFunction from "./myFunction"
describe(myFunction.name, () => {}) // member-form pathBoth fail on |
Fixes #954.
Problem
A type-only import is erased at compile time, so the identifier does not exist as a value at runtime:
The rule reports the string title and autofixes it to
describe(myFunction, ...), which does not compile —myFunctionis a type, not a value. Since the rule is fixable,--fixsilently breaks the file.The check only asked whether the binding was a
DefinitionType.ImportBinding, which is true for type-only imports as well.Fix
Skip bindings whose import is type-only, covering both syntaxes:
Applied to both report paths — the string-literal title and the
myFunction.namemember form, which has the same problem.Value imports are untouched, so every existing invalid case still reports and fixes as before.
Tests
Three valid cases added, one per syntax (
import type { x },import { type x },import type x). All three fail onmainand pass with the fix.Validation
vitest run→ 2378 passed (82 files)tsc --noEmit→ cleaneslint→ cleanprettier --check→ clean