fix(isolated-declarations): False positive for class private getter with non-inferrable return type (#5987)

Fixes a case missing from https://github.com/oxc-project/oxc/pull/5964

Co-authored-by: MichaelMitchell-at <=>
This commit is contained in:
michaelm 2024-09-23 03:28:29 -04:00 committed by GitHub
parent 859227e457
commit 97a2c41192
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 4 deletions

View file

@ -310,6 +310,10 @@ impl<'a> IsolatedDeclarations<'a> {
entry.1 = Some(&mut first_param.pattern.type_annotation);
}
MethodDefinitionKind::Get => {
if method.accessibility.is_some_and(TSAccessibility::is_private) {
continue;
}
let function = &mut method.value;
if function.return_type.is_none() {
function.return_type = self.infer_function_return_type(function);

View file

@ -58,8 +58,14 @@ export class PrivateFieldsWithConstructorAssignments {
export class PrivateMethodClass {
private good(a): void {}
private get goodGetter() {
return {[('x')]: 1};
}
}
export class PublicMethodClass {
public bad(a): void {}
public get badGetter() {
return {[('x')]: 1};
}
}

View file

@ -53,21 +53,32 @@ export declare class PrivateFieldsWithConstructorAssignments {
}
export declare class PrivateMethodClass {
private good;
private get goodGetter();
}
export declare class PublicMethodClass {
bad(a): void;
get badGetter(): {};
}
==================== Errors ====================
x TS9038: Computed property names on class or object literals cannot be
| inferred with --isolatedDeclarations.
,-[69:14]
68 | public get badGetter() {
69 | return {[('x')]: 1};
: ^^^^^
70 | }
`----
x TS9011: Parameter must have an explicit type annotation with
| --isolatedDeclarations.
,-[64:14]
63 | export class PublicMethodClass {
64 | public bad(a): void {}
,-[67:14]
66 | export class PublicMethodClass {
67 | public bad(a): void {}
: ^
65 | }
68 | public get badGetter() {
`----