Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand All @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions crates/oxc_isolated_declarations/tests/fixtures/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
4 changes: 4 additions & 0 deletions crates/oxc_isolated_declarations/tests/snapshots/class.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ export declare abstract class Qux {
bar(): void;
baz(): void;
}
export declare class Baz {
readonly prop1: 'some string';
prop2: string;
}