fix(isolated-declarations): infer failed if there are two setter/getter methods that need to be inferred (#5967)

This commit is contained in:
Dunqing 2024-09-22 13:41:47 +00:00
parent c84bd28a9c
commit fd1c46ca9e
3 changed files with 21 additions and 9 deletions

View file

@ -29,12 +29,12 @@ impl<'a> IsolatedDeclarations<'a> {
return;
};
let entry = method_annotations.entry(name).or_default();
let entry = method_annotations.entry(name.clone()).or_default();
entry.0 |= first_param.pattern.type_annotation.is_none();
entry.1 = Some(&mut first_param.pattern.type_annotation);
}
TSMethodSignatureKind::Get => {
let entry = method_annotations.entry(name).or_default();
let entry = method_annotations.entry(name.clone()).or_default();
entry.0 |= method.return_type.is_none();
entry.2 = Some(&mut method.return_type);
}
@ -43,13 +43,12 @@ impl<'a> IsolatedDeclarations<'a> {
});
for (requires_inference, param, return_type) in method_annotations.into_values() {
if !requires_inference {
return;
}
if let (Some(Some(annotation)), Some(option)) | (Some(option), Some(Some(annotation))) =
(param, return_type)
{
option.replace(annotation.clone_in(self.ast.allocator));
if requires_inference {
if let (Some(Some(annotation)), Some(option))
| (Some(option), Some(Some(annotation))) = (param, return_type)
{
option.replace(annotation.clone_in(self.ast.allocator));
}
}
}
}

View file

@ -17,4 +17,11 @@ export interface I {
export interface Ref<T = any, S = T> {
get value(): T
set value(_: S)
}
export interface MultipleSetterAndGetter {
get ok(): string
set ok(_: string)
get bad() // infer return type
set bad(_: string)
}

View file

@ -31,3 +31,9 @@ export interface Ref<
get value(): T;
set value(_: S);
}
export interface MultipleSetterAndGetter {
get ok(): string;
set ok(_: string);
get bad(): string;
set bad(_: string);
}