Skip to content

Commit b7e67fa

Browse files
fix(checker): narrow accessibility check for typeof parameters in type queries
Refined the accessibility check for parameter symbols to only apply when they are part of a TypeQuery. This prevents parameter identifiers used as computed property names in type printing from being incorrectly treated as accessible unique-symbol-like keys.
1 parent c000090 commit b7e67fa

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6160,7 +6160,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
61606160
}
61616161
// Parameters are always in scope within their enclosing function; `typeof paramName` in a
61626162
// return type annotation is valid regardless of method visibility (public, protected, private).
6163-
if (symbol.declarations && every(symbol.declarations, isParameter)) {
6163+
// Narrow this exception to TypeQuery nodes only (e.g. `typeof param`) so that parameter
6164+
// identifiers used as computed property names in type printing are not incorrectly treated
6165+
// as accessible unique-symbol-like keys.
6166+
if (symbol.declarations && every(symbol.declarations, isParameter) && isPartOfTypeQuery(entityName)) {
61646167
return { accessibility: SymbolAccessibility.Accessible };
61656168
}
61666169
// Verify if the symbol is accessible

tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export const updateIfChanged = <T>(t: T) => {
104104
> : ^
105105
>update : (u: U) => T
106106
> : ^ ^^ ^^^^^
107-
>Object.assign(Array.isArray(u) ? [] : {}, u, { [key]: v }) : U & { [key]: Value<K, U>; }
108-
> : ^^^^^^ ^^^^^^^^^^^ ^^
107+
>Object.assign(Array.isArray(u) ? [] : {}, u, { [key]: v }) : U & { [x: string]: Value<K, U>; }
108+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109109
>Object.assign : { <T_1 extends {}, U_1>(target: T_1, source: U_1): T_1 & U_1; <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V; <T_1 extends {}, U_1, V, W>(target: T_1, source1: U_1, source2: V, source3: W): T_1 & U_1 & V & W; (target: object, ...sources: any[]): any; }
110110
> : ^^^^^^^^^^^^^^^ ^^^^^^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^^^^^^^ ^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^^^^^^^^^^^^^ ^^^^^^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^^ ^^^ ^^ ^^^^^ ^^ ^^^ ^^^
111111
>Object : ObjectConstructor
@@ -130,8 +130,8 @@ export const updateIfChanged = <T>(t: T) => {
130130
> : ^^
131131
>u : U
132132
> : ^
133-
>{ [key]: v } : { [key]: Value<K, U>; }
134-
> : ^^ ^^^^^^^^^^^ ^^
133+
>{ [key]: v } : { [x: string]: Value<K, U>; }
134+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135135
>[key] : Value<K, U>
136136
> : ^^^^^^^^^^^
137137
>key : K

0 commit comments

Comments
 (0)