microsoft / microsoft/TypeScript
Find All References does not report references in mapped types
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
- find all references mapped type
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about (n/a)
TypeScript Version 5.3.3
⏯ Playground Link
💻 Code
export interface Literal {
kind: "literal";
value: number;
}
export type Expr = Literal;
export type VisitorMapped = {
[Kind in Expr["kind"]]: (expr: Extract<Expr, { kind: Kind }>) => number;
};
export type VisitorDirect = {
literal: (expr: Literal) => number;
}
export class InterpreterMapped implements VisitorMapped {
// 😔 Go to References on "literal" takes you to this line, not to line 8.
literal(expr: Literal): number {
return expr.value;
}
}
export class InterpreterDirect implements VisitorDirect {
// 💯 Go to References on "literal" show you this line and line 12
literal(expr: Literal): number {
return expr.value;
}
}
🙁 Actual behavior
"Go to References" / "Find All References" has different behaviors for the two literals:
- for
literalinInterpreterDirectit shows two references (inVisitorDirectandInterpreterDirect) - for
literalinInterpreterMappedit only shows the reference inInterpreterMapped, not inVisitorMapped.
🙂 Expected behavior
I'd expect "Go to References" / "Find All References" to report two references for both of the literals. The mapped type is a reference, even if it doesn't contain the identifier "literal" directly.
Additional information about the issue
This came up with Knip, which uses "find all references" to detect dead code. In this case this behavior caused a false positive: https://github.com/webpro/knip/issues/450
Possibly related to https://github.com/microsoft/TypeScript/issues/44643
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the linked Playground reproduction and compare Find All References for the mapped and direct visitor types. No source file or test is named, so trace the references implementation from that behavior. Done means both occurrences report the mapped-type member and the direct member consistently, with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100