Microsoft/TypeScript
GitHub ã§èŠãTS4055 when generating declaration for return type that uses type of paramter for protected methods
Open
#61,591 opened on 2025幎4æ18æ¥
BugDomain: Declaration EmitHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
TS4055 declaration protected return typeof parameter
ð Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about declarations
⯠Playground Link
ð» Code
export interface Properties {
propertyA: number;
propertyB: string;
}
export function getPropertyValue_Ok(
properties: Properties,
propertyName: keyof Properties,
): Properties[typeof propertyName] {
return properties[propertyName];
}
export class A {
public getPropertyValue_Ok(
properties: Properties,
propertyName: keyof Properties,
): Properties[typeof propertyName] {
return properties[propertyName];
}
// error TS4055: Return type of public method from exported class has or is using private name 'propertyName'.
protected getPropertyValue_Error(
properties: Properties,
propertyName: keyof Properties,
): Properties[typeof propertyName] {
return properties[propertyName];
}
// error TS4073: Parameter 'propertyValue' of public method from exported class has or is using private name 'propertyName'.
protected setPropertyValue_Error(
properties: Properties,
propertyName: keyof Properties,
propertyValue: Properties[typeof propertyName],
) {
// TODO
}
}
ð Actual behavior
The protected methods fail to generate declaration with TS4055 or TS4073.
ð Expected behavior
The protected methods should be able to generate declaration similar to the public method or function.
Additional information about the issue
I wonder if there's a way to temporarily suppress this error, becuase ts-ignore doesn't seem to work when generating declaration.