GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — API: getTypeAtLocation returns the error type for an identifier inside a type reference · Issue #65686 · microsoft/TypeScript

API: getTypeAtLocation returns the error type for an identifier inside a type reference #65686

New issue
Copy link
New issue
Copy link
Backlog
Backlog
API: getTypeAtLocation returns the error type for an identifier inside a type reference#65686
Copy link

Description

@LukasTy
Lukas Tyla (LukasTy)
opened on Nov 26, 2026
Issue body actions

TypeScript Version

The tested TypeScript version is 7.1.0-dev.20261126.1. 7.1.0-beta gives the same result. The expected result is from 6.0.3.

User Goal

The user maintains a documentation extractor that walks the AST and asks the checker for the type of each node. I compared the 6.0 checker API with the 7.1 typescript/sync API on the extractor's test inputs, to plan the port to 7.1.

Setup and Action

src/index.ts:

interface Foo { a: number }
declare namespace NS { interface Bar { b: string } }

export declare let x: Foo;
export declare let y: NS.Bar;

tsconfig.json:

{ "compilerOptions": { "strict": true, "noEmit": true }, "include": ["src"] }

repro.mjs (run node repro.mjs):

import path from 'node:path';
import { API } from 'typescript/sync';
import { isIdentifier, isQualifiedName, isTypeReferenceNode } from 'typescript/ast/is';

const config = path.resolve('tsconfig.json');
const api = new API({ cwd: process.cwd() });
const snapshot = api.createSnapshot({ openProjects: [config] });
const { program, checker } = snapshot.getConfiguredProject(config);
const sourceFile = program.getSourceFile(path.resolve('src/index.ts'));
const text = (node) => sourceFile.text.slice(node.pos, node.end).trim();

function visit(node) {
  const isTypeName =
    isIdentifier(node) &&
    (isTypeReferenceNode(node.parent) || (isQualifiedName(node.parent) && node.parent.right === node));
  if (isTypeReferenceNode(node) || isTypeName) {
    const type = checker.getTypeAtLocation(node);
    console.log(`${isTypeName ? 'Identifier   ' : 'TypeReference'} ${text(node).padEnd(6)} -> ${checker.typeToString(type)}`);
  }
  node.forEachChild(visit);
}
sourceFile.forEachChild(visit);
snapshot.dispose();
api.close();

Expected and Actual Behavior

What actually happened: getTypeAtLocation returns the error type for Foo in x: Foo and for Bar in NS.Bar. The enclosing TypeReference node gives the correct type.

TypeReference Foo    -> Foo
Identifier    Foo    -> any
TypeReference NS.Bar -> Bar
Identifier    Bar    -> any

What I expected: the declared type of the referenced symbol, as in 6.0.3:

TypeReference Foo    -> Foo
Identifier    Foo    -> Foo
TypeReference NS.Bar -> Bar
Identifier    Bar    -> Bar

Agent Info

Claude Code 2.1.198 + Claude Opus 5.5 + Skill Version 1.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.