fix(isolated-declarations): Report uninferrable types in arrays (#6084)

This commit is contained in:
michaelm 2024-09-26 19:31:22 -04:00 committed by GitHub
parent 87595286ce
commit 418ae25f3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 1 deletions

View file

@ -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
}),
}
}));

View file

@ -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

View file

@ -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 ====================
@ -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
: ^^^^^^
`----