Closed
Description
🔎 Search Terms
transpile, output, return statement
🕗 Version & Regression Information
- This changed between versions
4.5.5
and4.6.0
. Versions4.6.1
,4.6.2
,4.7.4
,4.8.4
,4.9.5
,5.0.4
,5.1.6
,5.2.2
,5.3.3
,5.4.5
,5.5.4
,5.6.3
,5.7.0-beta
, and5.7.0-dev.20241020
(aka the ones accessible from the TS version dropdown on the Playground, along with4.6.1
) have all been explicitly tested on the Playground and all exhibit the behaviour—presumably, the versions in between do too.
⏯ Playground Link
💻 Code
declare let x: number | undefined
// no comment and no 'as' = okay
function a() {
return (
x
) = 1;
}
function b() {
return (
// only a comment = okay
x
) = 1;
}
// only an 'as' = okay
function c() {
return (
x as number
) = 1;
}
function d() {
return (
// with the comment + 'as', it breaks
x as number
) = 1;
}
which transpiles to:
"use strict";
// no comment and no 'as' = okay
function a() {
return (x) = 1;
}
function b() {
return (
// only a comment = okay
x) = 1;
}
// only an 'as' = okay
function c() {
return x = 1;
}
function d() {
return
// with the comment + 'as', it breaks
x = 1;
}
🙁 Actual behavior
The issue is function d
—this function will always return undefined
at runtime
🙂 Expected behavior
As with versions prior to 4.6.0
, function d
should be transpiled as:
function d() {
return (
// with the comment + 'as', it breaks
x) = 1;
}
Additional information about the issue
No response