Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/five-flies-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/language-service": patch
---

Fix `getTypeAtLocation` to ignore type-only heritage expressions like `interface X extends Effect.Effect<...>` so the language service no longer triggers bogus TS2689 diagnostics.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no codefixes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// no diagnostics
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as Effect from "effect/Effect"

export interface Abc extends Effect.Effect<never, never, never> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no codefixes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// no diagnostics
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import * as Effect from "effect/Effect"

export interface Abc extends Effect.Effect<never, never, never> {}
43 changes: 43 additions & 0 deletions packages/language-service/src/core/TypeCheckerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,54 @@ export function makeTypeCheckerUtils(
if (node.parent && ts.isJsxClosingElement(node.parent) && node.parent.tagName === node) return
if (node.parent && ts.isJsxAttribute(node.parent) && node.parent.name === node) return

if (isInsideTypeOnlyHeritageExpression(node)) return

if (ts.isExpression(node) || ts.isTypeNode(node)) {
return typeChecker.getTypeAtLocation(node)
}
}

function isInsideTypeOnlyHeritageExpression(node: ts.Node): boolean {
if (ts.isExpressionWithTypeArguments(node)) {
return isTypeOnlyHeritageClause(node.parent)
}

if (!ts.isIdentifier(node) && !ts.isPropertyAccessExpression(node)) {
return false
}

for (let current = node.parent; current; current = current.parent) {
if (ts.isPropertyAccessExpression(current)) {
continue
}

if (ts.isExpressionWithTypeArguments(current)) {
return isTypeOnlyHeritageClause(current.parent)
}

return false
}

return false
}

function isTypeOnlyHeritageClause(node: ts.Node | undefined): boolean {
if (!node || !ts.isHeritageClause(node)) {
return false
}

const container = node.parent
if (!container) {
return false
}

if (ts.isInterfaceDeclaration(container)) {
return true
}

return ts.isClassLike(container) && node.token === ts.SyntaxKind.ImplementsKeyword
}

function resolveToGlobalSymbol(symbol: ts.Symbol): ts.Symbol {
if (symbol.flags & ts.SymbolFlags.Alias) {
symbol = typeChecker.getAliasedSymbol(symbol)
Expand Down
Loading