mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(isolated_declarations): inferring literal types for readonly class fileds (#4027)
This commit is contained in:
parent
b66ad0b675
commit
da628399fa
3 changed files with 23 additions and 3 deletions
|
|
@ -66,7 +66,11 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
.value
|
||||
.as_ref()
|
||||
.and_then(|expr| {
|
||||
let ts_type = self.infer_type_from_expression(expr);
|
||||
let ts_type = if property.readonly {
|
||||
self.transform_expression_to_ts_type(expr)
|
||||
} else {
|
||||
self.infer_type_from_expression(expr)
|
||||
};
|
||||
if ts_type.is_none() {
|
||||
self.error(property_must_have_explicit_type(property.key.span()));
|
||||
}
|
||||
|
|
@ -76,6 +80,9 @@ impl<'a> IsolatedDeclarations<'a> {
|
|||
})
|
||||
};
|
||||
|
||||
// TODO if inferred type_annotations is TSLiteral, it should stand as value,
|
||||
// so `field = 'string'` remain `field = 'string'` instead of `field: 'string'`
|
||||
|
||||
self.ast.class_property(
|
||||
property.r#type,
|
||||
property.span,
|
||||
|
|
|
|||
|
|
@ -6,10 +6,19 @@ export class Bar {
|
|||
public constructor(a: number = 0) {}
|
||||
}
|
||||
|
||||
export class Zoo { foo<F>(f: F): F { return f } }
|
||||
export class Zoo {
|
||||
foo<F>(f: F): F {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class Qux {
|
||||
abstract foo(): void;
|
||||
bar(): void {}
|
||||
baz(): void {}
|
||||
}
|
||||
}
|
||||
|
||||
export class Baz {
|
||||
readonly prop1 = 'some string';
|
||||
prop2 = 'another string';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,3 +18,7 @@ export declare abstract class Qux {
|
|||
bar(): void;
|
||||
baz(): void;
|
||||
}
|
||||
export declare class Baz {
|
||||
readonly prop1: 'some string';
|
||||
prop2: string;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue