Skip to content

Commit

Permalink
fix(isolated-declarations): Report uninferrable types in arrays (#6084)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMitchell-at authored Sep 26, 2024
1 parent 8759528 commit 418ae25
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion crates/oxc_isolated_declarations/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ impl<'a> IsolatedDeclarations<'a> {
}
_ => self
.transform_expression_to_ts_type(element.to_expression())
.map(TSTupleElement::from),
.map(TSTupleElement::from)
.or_else(|| {
self.error(inferred_type_of_expression(element.span()));
None
}),
}
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ const unaryB = -1_2n;
const unaryC = +"str"
const unaryD = typeof "str"
const unaryE = {E: -"str"} as const
const unaryF = [+"str"] as const
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ declare const unaryB = -1_2n;
declare const unaryC: unknown;
declare const unaryD: unknown;
declare const unaryE: {};
declare const unaryF: readonly [];
==================== Errors ====================
Expand Down Expand Up @@ -41,6 +42,14 @@ declare const unaryE: {};
17 | const unaryD = typeof "str"
18 | const unaryE = {E: -"str"} as const
: ^^^^^^
19 | const unaryF = [+"str"] as const
`----

x TS9013: Expression type can't be inferred with --isolatedDeclarations.
,-[19:17]
18 | const unaryE = {E: -"str"} as const
19 | const unaryF = [+"str"] as const
: ^^^^^^
`----
Expand Down

0 comments on commit 418ae25

Please sign in to comment.